I have a bash script that downloads some data, runs a process to import it, then sleeps for a little while (about an hour). It's running fine as a systemd service (on Ubuntu 16.04 & 18.04)

But I am afraid that interrupting the import process could leave the database in an inconsistent state, so I want to prevent it being interrupted. i.e. systemctl stop mything should block until the import process is finished. Other steps in the process can be interrupted at will.

Is there any easy way in a bash script to run a command and say "don't propagate the SIGKILL signal to this command"? (nohup blocks SIGHUP). For other, similar scripts, I've used bash's trap to 'catch' the signal which stops bash killing the process, but then the sleep isn't killed, so I had to run sleep in the background and wait on it (and then kill the sleep in the signal handler). Which seems overtly complicated.

Is there a better way? Is there a nosigkill command (like nohup) which will block sigkill for just that command?

  • @anx Yes using a systemd timer+service could be better than a service... Mar 27, 2019 at 10:26

1 Answer 1


You can set FinalKillSignal= to a different signal than SIGKILL, e.g. SIGCONT.

Note that systemd is going to get very annoyed at being unable to stop the service, but it should keep running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.