Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit with error if program goes fatal #733

Closed
mcd-php opened this issue Mar 29, 2016 · 7 comments
Closed

Exit with error if program goes fatal #733

mcd-php opened this issue Mar 29, 2016 · 7 comments

Comments

@mcd-php
Copy link

mcd-php commented Mar 29, 2016

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.

@misakwa
Copy link

misakwa commented Jun 19, 2016

@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.

@ankur4u007
Copy link

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

@OferE
Copy link

OferE commented Apr 24, 2017

+1

@ghost
Copy link

ghost commented Oct 16, 2017

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

@bronger
Copy link

bronger commented Jan 18, 2018

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.

@mnaberez
Copy link
Member

Duplicate of #712

@mnaberez mnaberez marked this as a duplicate of #712 Feb 23, 2018
@d10i
Copy link

d10i commented Feb 18, 2021

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.

mnaberez added a commit that referenced this issue Feb 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

7 participants