1

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?

Amandasaurus
  • 30,211
  • 62
  • 184
  • 246

1 Answers1

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.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940