在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:66Please respect copyright.PENANAnKRPjfy5mH
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)66Please respect copyright.PENANAx9yfTSylWR
-----------buda.service file content--------------66Please respect copyright.PENANAehEwW1lOn9
[Unit]66Please respect copyright.PENANAEmDGcmVBHw
Description=Buda Website Service 66Please respect copyright.PENANAQqhBHlQ5AQ
After=network.target
[Service]66Please respect copyright.PENANAo9MtnepZLg
Type=simple66Please respect copyright.PENANAUeWV7HJFtn
WorkingDirectory=/path/to/working/directory/66Please respect copyright.PENANAB5ZLKw3HxS
ExecStart=/path/of/exe_file66Please respect copyright.PENANAR0Ylzg9SWw
StandardOutput=append:/var/log/buda/2024_11_01.log66Please respect copyright.PENANAsyhvU5PXKB
StandardError=append:/var/log/buda/2024_11_01.log66Please respect copyright.PENANAOZqWhVozvN
Restart=always66Please respect copyright.PENANAYHl9yvXnE3
RestartSec=566Please respect copyright.PENANAI26per6wjI
User=root66Please respect copyright.PENANAeSK1zUhuGQ
Group=root
[Install]66Please respect copyright.PENANAoV5R4FzEVY
WantedBy=multi-user.target66Please respect copyright.PENANAQ8UHijgxTD
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:66Please respect copyright.PENANAnDhAOJX6bQ
systemctl daemon-reload66Please respect copyright.PENANAylWAHFQ1s7
systemctl enable buda66Please respect copyright.PENANAQ7DaaCjYSp
systemctl start buda66Please respect copyright.PENANAWnzaRLMj6N
systemctl status buda66Please respect copyright.PENANAv6P39eQpAQ
systemctl stop buda66Please respect copyright.PENANAXF8imeTS1S
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。66Please respect copyright.PENANAavVGJo60vG
journalctl -u buda
66Please respect copyright.PENANAmVFejpDWAi
本文参考资料66Please respect copyright.PENANAL8J3TXkKIG
stackoverflow66Please respect copyright.PENANAM2arjtOUB6
chatgpt-4o66Please respect copyright.PENANAWJbm3F4VVZ
gemini
66Please respect copyright.PENANA9wGMs2YqOO
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。