Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

supervisord event listener

I'm trying to configure an event listener for supervisord but can't get it to work. I just want to listen for PROCESS_STATE changes and run some python code triggering an urllib2request.

In my .conf I have:

[eventlistener:statechanges]
command=python listener.py
events=PROCESS_STATE

And in listener.py:

def run():    
    runFunc() # Function to trigger an urllib2request

if __name__ == '__main__':
    run()

Then the trigger won't start, it just enters the FATAL state after some retries.

statechanges entered FATAL state, too many start retries too quickly

Any ideas or does someone have an example of how to write a listener for supervisord?

like image 419
Carl Avatar asked Feb 26 '13 09:02

Carl


1 Answers

You can't just print random strings, supervisord listens at the stdout :)

How about this example from the docs:

import sys

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') # transition from ACKNOWLEDGED to READY
        line = sys.stdin.readline()  # read header line from stdin
        write_stderr(line) # print it out to stderr
        headers = dict([ x.split(':') for x in line.split() ])
        data = sys.stdin.read(int(headers['len'])) # read the event payload
        write_stderr(data) # print the event payload to stderr
        write_stdout('RESULT 2\nOK') # transition from READY to ACKNOWLEDGED

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

http://supervisord.org/events.html#example-event-listener-implementation

like image 140
Wolph Avatar answered Oct 23 '22 13:10

Wolph