Systemd,启动时运行服务

Systemd,启动时运行服务

我尝试使用 systemd 在系统启动时运行一些自定义服务。服务本身运行良好,我可以手动停止启动并重新启动它,但当要在系统启动时启用它时,服务会失败,我之前曾使用

sudo systemctl enable opimonitor

服务就是这样的。

[Unit]
Description=Opi Monitor service
After=network.target

[Service]
ExecStart=/home/arraiz/OPIstatus/start.sh
#Restart=always
WorkingDirectory=/home/arraiz/OPIstatus
User=arraiz
Group=arraiz

[Install]
WantedBy=multi-user.target

start.sh 是这样的。

git pull && python3 main.py

状态日志是

● opimonitor.service - Opi Monitor service
   Loaded: loaded (/etc/systemd/system/opimonitor.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2019-07-31 14:55:43 CEST; 1min 29s ago
  Process: 1114 ExecStart=/home/arraiz/OPIstatus/start.sh (code=exited, status=1/FAILURE)
 Main PID: 1114 (code=exited, status=1/FAILURE)

Jul 31 14:55:43 orangepipcplus systemd[1]: opimonitor.service: Service hold-off time over, scheduling restart.
Jul 31 14:55:43 orangepipcplus systemd[1]: opimonitor.service: Scheduled restart job, restart counter is at 5.
Jul 31 14:55:43 orangepipcplus systemd[1]: Stopped Opi Monitor service.
Jul 31 14:55:43 orangepipcplus systemd[1]: opimonitor.service: Start request repeated too quickly.
Jul 31 14:55:43 orangepipcplus systemd[1]: opimonitor.service: Failed with result 'exit-code'.
Jul 31 14:55:43 orangepipcplus systemd[1]: Failed to start Opi Monitor service.

谢谢。

答案1

服务文件中的 [Unit] 标签下有这个

After=printer.target network.target multi-user.target

相关内容