在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:68Please respect copyright.PENANARg1M3Dj8us
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)68Please respect copyright.PENANAXK0V2mX1Rt
-----------buda.service file content--------------68Please respect copyright.PENANAqXMLlWeYzk
[Unit]68Please respect copyright.PENANAHfAymNyFm7
Description=Buda Website Service 68Please respect copyright.PENANADxCYlnwThX
After=network.target
[Service]68Please respect copyright.PENANAquM7IAGeHT
Type=simple68Please respect copyright.PENANANAzQSXu8IL
WorkingDirectory=/path/to/working/directory/68Please respect copyright.PENANAQwH0vG8In7
ExecStart=/path/of/exe_file68Please respect copyright.PENANA6PKZTB6rHp
StandardOutput=append:/var/log/buda/2024_11_01.log68Please respect copyright.PENANAPcogWXift8
StandardError=append:/var/log/buda/2024_11_01.log68Please respect copyright.PENANAxPLwNrASIo
Restart=always68Please respect copyright.PENANAcgPSkJaBZp
RestartSec=568Please respect copyright.PENANAjAj5E6ZOZc
User=root68Please respect copyright.PENANAPDFBvv5LIO
Group=root
[Install]68Please respect copyright.PENANApE42AOFqyp
WantedBy=multi-user.target68Please respect copyright.PENANA5uuvtJsDLD
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:68Please respect copyright.PENANArJR1TtqDqT
systemctl daemon-reload68Please respect copyright.PENANAXtULm2g4hk
systemctl enable buda68Please respect copyright.PENANA2isVcrVrhR
systemctl start buda68Please respect copyright.PENANArTW0JHmboR
systemctl status buda68Please respect copyright.PENANADVxL6qbs7w
systemctl stop buda68Please respect copyright.PENANA241AELDmtZ
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。68Please respect copyright.PENANAb3YPEmgo5j
journalctl -u buda
68Please respect copyright.PENANA7sSdqx8Yc6
本文参考资料68Please respect copyright.PENANArYFnNrvxzg
stackoverflow68Please respect copyright.PENANAQ1wxNc2Fq6
chatgpt-4o68Please respect copyright.PENANAWZXHLJVwJu
gemini
68Please respect copyright.PENANAO2v6xkXu8a
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。