在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:62Please respect copyright.PENANADXZXEQaHR4
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)62Please respect copyright.PENANAMJ9JMUxnyA
-----------buda.service file content--------------62Please respect copyright.PENANA58kpeqI7SH
[Unit]62Please respect copyright.PENANA55eP2KBJhy
Description=Buda Website Service 62Please respect copyright.PENANAXAtBI0sqUC
After=network.target
[Service]62Please respect copyright.PENANA83LNgCpPtO
Type=simple62Please respect copyright.PENANAja3C1FdyNb
WorkingDirectory=/path/to/working/directory/62Please respect copyright.PENANAv0HShSeMuG
ExecStart=/path/of/exe_file62Please respect copyright.PENANAtwlbAqm8Xn
StandardOutput=append:/var/log/buda/2024_11_01.log62Please respect copyright.PENANAcNlDScpb9L
StandardError=append:/var/log/buda/2024_11_01.log62Please respect copyright.PENANAH4g7QCQGaB
Restart=always62Please respect copyright.PENANA2nCE3IvNVe
RestartSec=562Please respect copyright.PENANAJbakd2dQs2
User=root62Please respect copyright.PENANAvYViPppkIE
Group=root
[Install]62Please respect copyright.PENANAHfTkdAaAKE
WantedBy=multi-user.target62Please respect copyright.PENANAgQTwvfFjk0
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:62Please respect copyright.PENANAtSsRaEBlYS
systemctl daemon-reload62Please respect copyright.PENANAYu5aoMkS89
systemctl enable buda62Please respect copyright.PENANAiQgsSxivuK
systemctl start buda62Please respect copyright.PENANAEGUACpo7O5
systemctl status buda62Please respect copyright.PENANAlxSfY7rv8u
systemctl stop buda62Please respect copyright.PENANAYpybjkH7fG
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。62Please respect copyright.PENANABeYrRNKcGU
journalctl -u buda
62Please respect copyright.PENANAPsc0yuO74R
本文参考资料62Please respect copyright.PENANAtdgu0DqFVm
stackoverflow62Please respect copyright.PENANABgPGUP2quR
chatgpt-4o62Please respect copyright.PENANABIH1xAoPk0
gemini
62Please respect copyright.PENANA9SMEDgZ4zc
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。