在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:61Please respect copyright.PENANAwJ6xy0q8zw
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)61Please respect copyright.PENANAbxKEziF16t
-----------buda.service file content--------------61Please respect copyright.PENANAfGYAqb8vas
[Unit]61Please respect copyright.PENANAf0cqt2lrke
Description=Buda Website Service 61Please respect copyright.PENANAVb4PEt8vzN
After=network.target
[Service]61Please respect copyright.PENANAMYn38sFEuk
Type=simple61Please respect copyright.PENANAXgPKkYGzcK
WorkingDirectory=/path/to/working/directory/61Please respect copyright.PENANASg9sf5trXm
ExecStart=/path/of/exe_file61Please respect copyright.PENANA9qgStD50jk
StandardOutput=append:/var/log/buda/2024_11_01.log61Please respect copyright.PENANArK2sSc288k
StandardError=append:/var/log/buda/2024_11_01.log61Please respect copyright.PENANAiyDQwMOSGq
Restart=always61Please respect copyright.PENANArZrkB2G9eF
RestartSec=561Please respect copyright.PENANA6azfjs91tq
User=root61Please respect copyright.PENANAcNRSOunhuU
Group=root
[Install]61Please respect copyright.PENANAzVnedQS9AS
WantedBy=multi-user.target61Please respect copyright.PENANAfwfbHInSLS
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:61Please respect copyright.PENANAShx4tKlznO
systemctl daemon-reload61Please respect copyright.PENANAXx7yQjZbab
systemctl enable buda61Please respect copyright.PENANA6w4V0O8pwI
systemctl start buda61Please respect copyright.PENANA6G4NTHlUxX
systemctl status buda61Please respect copyright.PENANA8ymIU9CW7B
systemctl stop buda61Please respect copyright.PENANAmDaBYgZrIH
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。61Please respect copyright.PENANAt2BWEzm847
journalctl -u buda
61Please respect copyright.PENANAkvWVhtU3rD
本文参考资料61Please respect copyright.PENANAunf7aQBFKU
stackoverflow61Please respect copyright.PENANAc92g26sGt2
chatgpt-4o61Please respect copyright.PENANAI4jjOapvV7
gemini
61Please respect copyright.PENANAQUklsJYhEi
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。