在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:38Please respect copyright.PENANAAQfN4N8t3M
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)38Please respect copyright.PENANAkEtwGs1hWs
-----------buda.service file content--------------38Please respect copyright.PENANALylVFVU22K
[Unit]38Please respect copyright.PENANAUQjCEDT4tU
Description=Buda Website Service 38Please respect copyright.PENANACXOmYFgUrl
After=network.target
[Service]38Please respect copyright.PENANAvXPMMu08ZH
Type=simple38Please respect copyright.PENANAvO5TuzvJYz
WorkingDirectory=/path/to/working/directory/38Please respect copyright.PENANANdLZp9DaQp
ExecStart=/path/of/exe_file38Please respect copyright.PENANAwqPah4TMpZ
StandardOutput=append:/var/log/buda/2024_11_01.log38Please respect copyright.PENANAdqMUwRwb15
StandardError=append:/var/log/buda/2024_11_01.log38Please respect copyright.PENANAl8QzcQ9zdH
Restart=always38Please respect copyright.PENANAp6L19jtqg6
RestartSec=538Please respect copyright.PENANAVkJur7czLV
User=root38Please respect copyright.PENANAdQl3PbeNdl
Group=root
[Install]38Please respect copyright.PENANA6J5YLTDCzT
WantedBy=multi-user.target38Please respect copyright.PENANA9ZeD46e2XU
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:38Please respect copyright.PENANA0llAStIDQ8
systemctl daemon-reload38Please respect copyright.PENANA7OxPOxGvm2
systemctl enable buda38Please respect copyright.PENANAfdEGa1JExG
systemctl start buda38Please respect copyright.PENANAf2nnZa1I5D
systemctl status buda38Please respect copyright.PENANABLf2uuBoQQ
systemctl stop buda38Please respect copyright.PENANAtMLxM5jbjR
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。38Please respect copyright.PENANAYPzOPgRrTs
journalctl -u buda
38Please respect copyright.PENANACkynpvVJVg
本文参考资料38Please respect copyright.PENANAzIsTmK6RCU
stackoverflow38Please respect copyright.PENANAoZOCEdT3hY
chatgpt-4o38Please respect copyright.PENANAqM8RqNtL8f
gemini
38Please respect copyright.PENANAbDsUl0EVWQ
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。