在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:42Please respect copyright.PENANAS6nKPOXh6g
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)42Please respect copyright.PENANAw6KVOQ5Lup
-----------buda.service file content--------------42Please respect copyright.PENANAWErJNMPJha
[Unit]42Please respect copyright.PENANAIJrhEzDfXo
Description=Buda Website Service 42Please respect copyright.PENANAaIsXY4Y3sn
After=network.target
[Service]42Please respect copyright.PENANAHVZ7TxYQfG
Type=simple42Please respect copyright.PENANA5m2lCCTmJb
WorkingDirectory=/path/to/working/directory/42Please respect copyright.PENANAgWdhOpsIVn
ExecStart=/path/of/exe_file42Please respect copyright.PENANAyS3PID1ATG
StandardOutput=append:/var/log/buda/2024_11_01.log42Please respect copyright.PENANAmOTsPRf5bJ
StandardError=append:/var/log/buda/2024_11_01.log42Please respect copyright.PENANA9YXS8v2xeI
Restart=always42Please respect copyright.PENANA9xc1YXwEAj
RestartSec=542Please respect copyright.PENANAwwnzdIZhBB
User=root42Please respect copyright.PENANA1wbcZcM4Sg
Group=root
[Install]42Please respect copyright.PENANAbpM8fCbuxZ
WantedBy=multi-user.target42Please respect copyright.PENANAHq2NxPUgyD
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:42Please respect copyright.PENANA8rTvE3QPPN
systemctl daemon-reload42Please respect copyright.PENANAjyRl1xNbAI
systemctl enable buda42Please respect copyright.PENANAP98GlGFuep
systemctl start buda42Please respect copyright.PENANALJyY2sN2No
systemctl status buda42Please respect copyright.PENANAhaBW0G7F8C
systemctl stop buda42Please respect copyright.PENANAEGrwrX4uGl
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。42Please respect copyright.PENANAq8ivpIAiww
journalctl -u buda
42Please respect copyright.PENANAUGxXghc3L5
本文参考资料42Please respect copyright.PENANAHlpsWe1lal
stackoverflow42Please respect copyright.PENANAslZXygzV9E
chatgpt-4o42Please respect copyright.PENANAnPNz9siCC6
gemini
42Please respect copyright.PENANA4ZkhnvnFo1
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。