在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:72Please respect copyright.PENANARrWoxN0npz
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)72Please respect copyright.PENANAdePgqXlSTT
-----------buda.service file content--------------72Please respect copyright.PENANARwFLntAfdR
[Unit]72Please respect copyright.PENANA3iDHnv5Tt6
Description=Buda Website Service 72Please respect copyright.PENANAWPwCaK9B3z
After=network.target
[Service]72Please respect copyright.PENANAosSqeUCTII
Type=simple72Please respect copyright.PENANAmVBLvVMxp2
WorkingDirectory=/path/to/working/directory/72Please respect copyright.PENANAw6PAfGkpTp
ExecStart=/path/of/exe_file72Please respect copyright.PENANAaW1aWlqzEt
StandardOutput=append:/var/log/buda/2024_11_01.log72Please respect copyright.PENANA1371iRwtfb
StandardError=append:/var/log/buda/2024_11_01.log72Please respect copyright.PENANAxnvcSIzOhM
Restart=always72Please respect copyright.PENANAQcgBlftzMK
RestartSec=572Please respect copyright.PENANAWq6cTxNHZd
User=root72Please respect copyright.PENANAuw6Mttjgdb
Group=root
[Install]72Please respect copyright.PENANAy73JGu02Fy
WantedBy=multi-user.target72Please respect copyright.PENANAGvD5vx6w7U
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:72Please respect copyright.PENANAQGpFN932pC
systemctl daemon-reload72Please respect copyright.PENANASUn6bzQu8d
systemctl enable buda72Please respect copyright.PENANA2j6wEp8vhZ
systemctl start buda72Please respect copyright.PENANAIjcNfLdUli
systemctl status buda72Please respect copyright.PENANA5gdlU3K8LT
systemctl stop buda72Please respect copyright.PENANAiiWuEx5SPU
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。72Please respect copyright.PENANAFeKi3Wvlfp
journalctl -u buda
72Please respect copyright.PENANAWvbKLl2lxm
本文参考资料72Please respect copyright.PENANAcUpOwcyfxF
stackoverflow72Please respect copyright.PENANAUnuR9pSdPi
chatgpt-4o72Please respect copyright.PENANAKWH98hB4Nm
gemini
72Please respect copyright.PENANA5ZHOtZHATU
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。