0
votes

I have a systemd script that works correctly if I call it directly or if I call if via systemd like:

systemctl stop XXX.service

But the script fails to work when the system is rebooted or shutdown.

Here is the systemd script:

[Unit]
Description=Run Scripts at Start and Stop
After=syslog.target network.target

[Service]
Type=oneshot
User=root
Group=root
RemainAfterExit=true
ExecStart=/usr/bin/echo start
ExecStop=/usr/bin/killall -u xxx
ExecStopPost=/bbb/stop_back.sh
TimeoutStopSec=5min 35s

[Install]
WantedBy=multi-user.target
1
I'm voting to close this question as off-topic because it's not about programming; try unix.stackexchange.commustaccio

1 Answers

2
votes

Adding the "Requires" line seemed to be the key thing to make it work.

[Unit]
Description = Run Scripts at Start and Stop
Requires = syslog.target network.target
After = syslog.target network.target
    
[Service]
Type = oneshot
User = root
Group = root
RemainAfterExit = true
ExecStart = /usr/bin/echo start
ExecStop = /usr/bin/killall -u xxx
ExecStopPost = /bbb/stop_back.sh
TimeoutStopSec = 5min 35s
    
[Install]
WantedBy = multi-user.target