Supervisor: Exit with error if program goes fatal

Created on 29 Mar 2016  ·  7Comments  ·  Source: Supervisor/supervisor

postgresql + filebeat + cron + supervisord = dead postgresql for whatever error in it, but still live Docker container

Is it possible to gracefully exit with error code and proper messages, if some program goes to fatal state ?

Read docs thoroughly, not found.

Most helpful comment

In the container world, this is a very typical scenario (i.e. you want an aborting container if anything goes wrong). Thus, I think a supervisord option like “exit if one program could not be launched” would be very helpful.

All 7 comments

@mcd-php I was able to achieve something similar by using an event listener as described here. My only issue now is that supervisord exits with status 0 and causes the container to exit with the same status. I was expecting status code > 128 when the listener killed supervisord. Let me know if this works for you.
I'm still not sure if the exit status is a bug in supervisor or not.

Any update on this, facing the same issue as mentioned by @misakwa

+1

This is actually quite easy to achieve with a little python script:

[eventlistener:quit_on_failure]
events=PROCESS_STATE_FATAL
command=/usr/local/bin/manage-supervisord

/usr/local/bin/manage-supervisord:

#!/usr/bin/python
import sys
import os
import signal

def write_stdout(s):
    sys.stdout.write(s)
    sys.stdout.flush()

def write_stderr(s):
    sys.stderr.write(s)
    sys.stderr.flush()

def main():
    while 1:
        write_stdout('READY\n')
        line = sys.stdin.readline()
        os.kill(1, signal.SIGTERM)
        write_stdout('RESULT 2\nOK')

if __name__ == '__main__':
    main()
    import sys

For a complete Docker image doing exactly that, check my repo out: https://github.com/opsbears/docker-supervisord

In the container world, this is a very typical scenario (i.e. you want an aborting container if anything goes wrong). Thus, I think a supervisord option like “exit if one program could not be launched” would be very helpful.

Duplicate of #712

Sorry to write in an old issue but I think this could be useful to others bumping into this problem. @janoszen's script above could be replaced with:

[eventlistener:quit_on_failure]
events=PROCESS_STATE_FATAL
command=sh -c 'while true; do echo "READY"; read line; kill -15 1; echo "RESULT 2"; echo "OK"; done'

This saves you from having a separate file and from installing Python if you don't need it from anything else.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivan1986 picture ivan1986  ·  49Comments

ido50 picture ido50  ·  95Comments

guettli picture guettli  ·  96Comments

grandfatha picture grandfatha  ·  57Comments

mminer picture mminer  ·  41Comments