0

I have a script that runs infinitely at startup, and another script that shuts it down safely. The second script requires connection to a remote database. They are both declared in the same service as ExecStart and ExecStop respectively. I need the second script to block shutdown/reboot until it completes. Currently the first script works fine but the second script is terminated early. Here is what I have so far:

[Unit]
DefaultDependencies=no
Wants=network-online.target
After=network.target network-online.target
Before=reboot.target shutdown.target halt.target

[Service]
Type=oneshot
RemainAfterExit=true
User=test
ExecStart=/usr/bin/python /home/test/test.py
ExecStop=/usr/bin/sh /home/test/test
KillMode=none

[Install]
WantedBy=multi-user.target

I tried using the following: systemd to wait for command to complete before restart/shutdown or killing other processes but it did not solve my problem, and it seems like his are commands that run relatively quickly.

Mocking
  • 151

1 Answers1

3

I added the following and it worked:

TimeoutSec=300min

My final configuration is:

[Unit]
DefaultDependencies=no
Wants=network-online.target
After=network.target network-online.target
Before=reboot.target shutdown.target halt.target

[Service]
Type=simple
RemainAfterExit=true
User=test
ExecStart=/usr/bin/python /home/test/test.py
ExecStop=/usr/bin/sh /home/test/test
KillMode=none
TimeoutSec=300min

[Install]
WantedBy=multi-user.target

Note: I purposely did not make the TimeoutSec=infinity

Mocking
  • 151