0

I use Supervisor to manage processes. Is it possible to have Supervisor run a command when it receives a SIGTERM (or another signal)?

0

No, it's not possible to customize behaviour of Supervisor when it receives signal(s), without changing source code and adding that ability.

Only thing you can do is specify is the kill signal for the process when it is going to be stopped, via "stopsignal" option.

  • Good to know, thanks. I was looking into running some kind of clean up script after all processes stop. – Martin Preusse Jul 26 '14 at 10:32
0

Here is one approach to achieve what you want:

(1) Create a new shell script, let's call it woker.sh:

#!/bin/bash

function do_something {
  # do something
  exit 0
}

trap do_something SIGTERM

while true; do
  sleep 1
done

(2) Add above script file to your Supervisor configuration file supervisord.conf as a new program section:

[program:worker]
command=/usr/local/bin/worker.sh
stderr_logfile = /var/log/supervisord/worker-stderr.log
stdout_logfile = /var/log/supervisord/worker-stdout.log

You can find a real example here.

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.