在/etc/systemd/system/目录下创建一个新的<your_service_name>.service文件,例如buda.service,里面填入以下内容:65Please respect copyright.PENANA57ta5D9iRq
(特别要注意设置WorkingDirectory, 这将决定exe程序中的相对路径的解析结果。)65Please respect copyright.PENANAVkvOdhQtfB
-----------buda.service file content--------------65Please respect copyright.PENANAvf2hEoIrVX
[Unit]65Please respect copyright.PENANAJcHoJtf2z8
Description=Buda Website Service 65Please respect copyright.PENANABJO6WpbSgK
After=network.target
[Service]65Please respect copyright.PENANAYSU1vzP8X7
Type=simple65Please respect copyright.PENANAPH7iZhj1yO
WorkingDirectory=/path/to/working/directory/65Please respect copyright.PENANAWgxSLkcPie
ExecStart=/path/of/exe_file65Please respect copyright.PENANAgVxH1nTKO7
StandardOutput=append:/var/log/buda/2024_11_01.log65Please respect copyright.PENANAf5thoTrQPD
StandardError=append:/var/log/buda/2024_11_01.log65Please respect copyright.PENANAHCgVoUylfN
Restart=always65Please respect copyright.PENANAX6Plvf9Ruo
RestartSec=565Please respect copyright.PENANAGRJcYE7JPs
User=root65Please respect copyright.PENANA8rTV1QUd6L
Group=root
[Install]65Please respect copyright.PENANAgf3Z2di14s
WantedBy=multi-user.target65Please respect copyright.PENANATwQToUy6YB
-----------------------------------------------
然后执行下面的命令让服务生效,查看错误日志
# 重新加载systemd管理器配置:65Please respect copyright.PENANASXJFjo5p2W
systemctl daemon-reload65Please respect copyright.PENANAlKnby1VNKl
systemctl enable buda65Please respect copyright.PENANAl94DRjrQ2N
systemctl start buda65Please respect copyright.PENANAqVW7iOGXS0
systemctl status buda65Please respect copyright.PENANAp7OQGjZRA2
systemctl stop buda65Please respect copyright.PENANAdxRRQlYgK0
systemctl disable buda
#查看服务的日志输出,帮助调试和故障排除。65Please respect copyright.PENANAtd8CvoNem9
journalctl -u buda
65Please respect copyright.PENANAX3YfVHSmnp
本文参考资料65Please respect copyright.PENANAijMsd0LsNU
stackoverflow65Please respect copyright.PENANAJM2lRhZZo4
chatgpt-4o65Please respect copyright.PENANATwElCi495U
gemini
65Please respect copyright.PENANAIoQwvHORUr
如果您對Linux系統的使用、網站開發技術感興趣,邀請您加入淨明創建的「Linux + C語言 + Vue 網站開發技術學習交流微信羣」,請加淨明的微信(si_jinmin)以便拉您進羣。