在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:163Please respect copyright.PENANA0LKhT5heIC
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)163Please respect copyright.PENANAun8i539ZV5
-----------buda.service file content--------------163Please respect copyright.PENANAl3XQtQhwyK
[Unit]163Please respect copyright.PENANAUzVGyeuNQn
Description=Buda Website Service 163Please respect copyright.PENANAJgQAy2X179
After=network.target
[Service]163Please respect copyright.PENANAH703l9GN7t
Type=simple163Please respect copyright.PENANAtO0zam3DPi
WorkingDirectory=/path/to/working/directory/163Please respect copyright.PENANAKHL7MBvPzp
ExecStart=/path/of/exe_file163Please respect copyright.PENANAJdcVopbSp6
StandardOutput=append:/var/log/buda/2024_11_01.log163Please respect copyright.PENANAwaP7YG3W4m
StandardError=append:/var/log/buda/2024_11_01.log163Please respect copyright.PENANAF1LbG18Qs2
Restart=always163Please respect copyright.PENANAkd5e7wbS5f
RestartSec=5163Please respect copyright.PENANARSpvjS5JeA
User=root163Please respect copyright.PENANAWsTtjQcteX
Group=root
[Install]163Please respect copyright.PENANAZVBlBWci52
WantedBy=multi-user.target163Please respect copyright.PENANAYJAik7LVnj
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:163Please respect copyright.PENANAguzpSkHueD
systemctl daemon-reload163Please respect copyright.PENANAwz9VNwv94f
systemctl enable buda163Please respect copyright.PENANAH4vdBx5GmM
systemctl start buda163Please respect copyright.PENANA03xT48iX8R
systemctl status buda163Please respect copyright.PENANAyWd2eZ9xre
systemctl stop buda163Please respect copyright.PENANAw2IM2oRELQ
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。163Please respect copyright.PENANAGHNuff7lGp
journalctl -u buda
163Please respect copyright.PENANAoLxI5kFL5W
本文参考资料163Please respect copyright.PENANAcWecWQDw9x
stackoverflow163Please respect copyright.PENANAApwUNPpssm
chatgpt-4o163Please respect copyright.PENANAG2GEj6L6l3
gemini
163Please respect copyright.PENANAfNMBX0cDjj
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。