在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:64Please respect copyright.PENANARL9IdNBFZv
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)64Please respect copyright.PENANADXYG9ZtHXK
-----------buda.service file content--------------64Please respect copyright.PENANAetkZXfqiab
[Unit]64Please respect copyright.PENANACJSb4znIC3
Description=Buda Website Service 64Please respect copyright.PENANAjXnpyqjEvG
After=network.target
[Service]64Please respect copyright.PENANAuKOeTUXs3Y
Type=simple64Please respect copyright.PENANAZNM1FMOL7r
WorkingDirectory=/path/to/working/directory/64Please respect copyright.PENANAvBHSlTC3lf
ExecStart=/path/of/exe_file64Please respect copyright.PENANAZmtZSs1Ysr
StandardOutput=append:/var/log/buda/2024_11_01.log64Please respect copyright.PENANAAtj3z5W6JY
StandardError=append:/var/log/buda/2024_11_01.log64Please respect copyright.PENANAcImmINu721
Restart=always64Please respect copyright.PENANAnX3Qap5kAj
RestartSec=564Please respect copyright.PENANAhIsOmZN14h
User=root64Please respect copyright.PENANAvCBsFuuoIq
Group=root
[Install]64Please respect copyright.PENANAStfmyDkNa7
WantedBy=multi-user.target64Please respect copyright.PENANA4JKWSNCMOq
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:64Please respect copyright.PENANA4RzhoacZGb
systemctl daemon-reload64Please respect copyright.PENANAT8ARscEu5M
systemctl enable buda64Please respect copyright.PENANAAaI6IbCMZa
systemctl start buda64Please respect copyright.PENANAa5KXiaKeTZ
systemctl status buda64Please respect copyright.PENANApYN65McliP
systemctl stop buda64Please respect copyright.PENANANrju6mQy8M
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。64Please respect copyright.PENANAlJcdUtNiY9
journalctl -u buda
64Please respect copyright.PENANAk1vD2tNiI1
本文参考资料64Please respect copyright.PENANAt3kFbQ8xmK
stackoverflow64Please respect copyright.PENANA0ci1yEhSoR
chatgpt-4o64Please respect copyright.PENANAHGF787xDBa
gemini
64Please respect copyright.PENANAPY0tpUpEKF
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。