自动启动脚本(Systemd)崩溃

时间:2019-06-13 07:26:20

标签: systemd autostart

我想使用systemd自动启动我的脚本,该脚本执行git checkout,git pull(我确定不会发生冲突),然后运行python程序。我创建了显示任务的示例。但是它会定期崩溃。设置“ TimeoutStartSec = infinity”是否正确?也许我必须以其他方式来做到这一点?

TEST_DAEMON.py

#!/usr/bin/python3.7
while True:
    pass

TEST_DAEMON.sh

#!/bin/sh
cd /home/user/TEST_DAEMON/
git checkout master
git pull
/home/user/TEST_DAEMON/TEST_DAEMON.py

TEST_DAEMON.service

[Unit]
Description=TEST_DAEMON SERVICE

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
User=user
PIDFile=/var/run/test_daemon.pid
WorkingDirectory=/home/user/TEST_DAEMON
ExecStart=/home/user/TEST_DAEMON/TEST_DAEMON.py
Restart=always

==================================

sudo systemctl status TEST_DAEMON.service

● TEST_DAEMON.service - TEST_DAEMON SERVICE
   Loaded: loaded (/etc/systemd/system/TEST_DAEMON.service; enabled; vendor preset: enabled)
   Active: activating (start) since Thu 2019-06-13 10:11:01 MSK; 2min 26s ago
Cntrl PID: 7699 (TEST_DAEMON.sh)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/TEST_DAEMON.service
           ├─7699 /bin/sh /home/user/TEST_DAEMON/TEST_DAEMON.sh
           └─7713 /usr/bin/python3.7 /home/user/TEST_DAEMON/TEST_DAEMON.py


Part of log "journalctl -u TEST_DAEMON.service"

Jun 11 15:36:39 TEST_DAEMON.sh[30119]: Already on 'agents_manager'
Jun 11 15:36:39 TEST_DAEMON.sh[30119]: Your branch is up to date with 'origin/agents_manager'.
Jun 11 15:36:42 TEST_DAEMON.sh[30119]: Already up to date.
Jun 11 15:38:10 systemd[1]: TEST_DAEMON.service: Start operation timed out. Terminating.
Jun 11 15:38:10 systemd[1]: TEST_DAEMON.service: Failed with result 'timeout'.
Jun 11 15:38:10 systemd[1]: Failed to start TEST_DAEMON SERVICE.
Jun 11 15:38:10 systemd[1]: TEST_DAEMON.service: Service hold-off time over, scheduling restart.
Jun 11 15:38:10 systemd[1]: TEST_DAEMON.service: Scheduled restart job, restart counter is at 3.
Jun 11 15:38:10 systemd[1]: Stopped TEST_DAEMON SERVICE.
Jun 11 15:38:10 systemd[1]: Starting TEST_DAEMON SERVICE...
Jun 11 15:38:10 TEST_DAEMON.sh[30227]: Already on 'agents_manager'
Jun 11 15:38:10 TEST_DAEMON.sh[30227]: Your branch is up to date with 'origin/agents_manager'.
Jun 11 15:38:15 TEST_DAEMON.sh[30227]: Already up to date.
Jun 11 15:39:40 systemd[1]: TEST_DAEMON.service: Start operation timed out. Terminating.
Jun 11 15:39:40 systemd[1]: TEST_DAEMON.service: Failed with result 'timeout'.
Jun 11 15:39:40 systemd[1]: Failed to start TEST_DAEMON SERVICE.
Jun 11 15:39:40 systemd[1]: TEST_DAEMON.service: Service hold-off time over, scheduling restart.
Jun 11 15:39:40 systemd[1]: TEST_DAEMON.service: Scheduled restart job, restart counter is at 4.
Jun 11 15:39:40 systemd[1]: Stopped TEST_DAEMON SERVICE.
Jun 11 15:39:40 systemd[1]: Starting TEST_DAEMON SERVICE...
Jun 11 15:39:40 TEST_DAEMON.sh[30273]: Already on 'agents_manager'
Jun 11 15:39:40 TEST_DAEMON.sh[30273]: Your branch is up to date with 'origin/agents_manager'.
Jun 11 15:39:43 TEST_DAEMON.sh[30273]: Already up to date.

0 个答案:

没有答案