在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:39Please respect copyright.PENANA3nwYV407Op
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)39Please respect copyright.PENANAjnEp0GIvFV
-----------buda.service file content--------------39Please respect copyright.PENANAwiS6JOshO6
[Unit]39Please respect copyright.PENANAV9IazxHN98
Description=Buda Website Service 39Please respect copyright.PENANA3QflGRpT1v
After=network.target
[Service]39Please respect copyright.PENANAIBK0IMXh4E
Type=simple39Please respect copyright.PENANAsaKRLBslvG
WorkingDirectory=/path/to/working/directory/39Please respect copyright.PENANA207Mhr2a4t
ExecStart=/path/of/exe_file39Please respect copyright.PENANA7bgUalXnfd
StandardOutput=append:/var/log/buda/2024_11_01.log39Please respect copyright.PENANA9qUIV2XsTZ
StandardError=append:/var/log/buda/2024_11_01.log39Please respect copyright.PENANAZMeEjnGLYS
Restart=always39Please respect copyright.PENANAnvUEaMs966
RestartSec=539Please respect copyright.PENANAtZbu4WN7Q2
User=root39Please respect copyright.PENANAtve0wSAwvi
Group=root
[Install]39Please respect copyright.PENANA1BEEfI1WXU
WantedBy=multi-user.target39Please respect copyright.PENANAslulR7xOtV
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:39Please respect copyright.PENANA8spkNZP5Li
systemctl daemon-reload39Please respect copyright.PENANAYpYMsXJGxb
systemctl enable buda39Please respect copyright.PENANAGOkQa7w5T6
systemctl start buda39Please respect copyright.PENANAVQ3aebb23o
systemctl status buda39Please respect copyright.PENANAC58RrA5vdh
systemctl stop buda39Please respect copyright.PENANAIozAfoodxD
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。39Please respect copyright.PENANAAQl1K6jRoC
journalctl -u buda
39Please respect copyright.PENANAekaEaQyKHl
本文参考资料39Please respect copyright.PENANAtuwyHCFxFt
stackoverflow39Please respect copyright.PENANAWVIFnRIceC
chatgpt-4o39Please respect copyright.PENANAxaWspqJW48
gemini
39Please respect copyright.PENANAup2E0bSGtD
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。