Hi, i need to receive a process state event. So i use the event listener to do this. But now i can only receive the event about the event listener self, not other process. my configure file is below:
[program:sample]
directory=/data/
command=/bin/bash -c 'while sleep 1; do echo "test"; done'
redirect_stderr=true
log_stdout=true ; if true, log program stdout (default true)
log_stderr=true ; if true, log program stderr (def false)
stdout_logfile=/data/logs/supervisord/sample.log ; child log path, use NONE for none; default AUTO
stdout_logfile_maxbytes=50MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=3 ; # of logfile backups (default 10)
[program:cat]
directory=/data/
command=/bin/cat
redirect_stderr=true
log_stdout=true ; if true, log program stdout (default true)
log_stderr=true ; if true, log program stderr (def false)
stdout_logfile=/data/logs/supervisord/cat.log ; child log path, use NONE for none; default AUTO
stdout_logfile_maxbytes=50MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=3 ; # of logfile backups (default 10)
[eventlistener:event]
command=/opt/python/bin/python /etc/supervisord.d/event.py
events=PROCESS_STATE
redirect_stderr=true
log_stdout=true ; if true, log program stdout (default true)
log_stderr=true ; if true, log program stderr (def false)
stdout_logfile=/data/logs/supervisord/x.log ; child log path, use NONE for none; default AUTO
stdout_logfile_maxbytes=50MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=3 ; # of logfile backups (default 10)
buffer_size=10
my event.py
#! /opt/python/bin/python
import sys
from supervisor.childutils import listener
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 True:
headers, body = listener.wait(sys.stdin, sys.stdout)
body = dict([pair.split(":") for pair in body.split(" ")])
write_stderr("Headers: %r\n" % repr(headers))
write_stderr("Body: %r\n" % repr(body))
if headers["eventname"] == "PROCESS_STATE_RUNNING":
write_stderr("Process state running...\n")
if __name__ == '__main__':
main()
my log
Headers: "{'ver': '3.0', 'poolserial': '0', 'len': '60', 'server': 'supervisor', 'eventname': 'PROCESS_STATE_STARTING', 'serial': '117', 'pool': 'event'}"
Body: "{'from_state': 'STOPPED', 'processname': 'event', 'tries': '0', 'groupname': 'event'}"
READY
READY
Headers: "{'ver': '3.0', 'poolserial': '0', 'len': '60', 'server': 'supervisor', 'eventname': 'PROCESS_STATE_STARTING', 'serial': '133', 'pool': 'event'}"
Body: "{'from_state': 'STOPPED', 'processname': 'event', 'tries': '0', 'groupname': 'event'}"
READY
READY
Headers: "{'ver': '3.0', 'poolserial': '0', 'len': '60', 'server': 'supervisor', 'eventname': 'PROCESS_STATE_STARTING', 'serial': '145', 'pool': 'event'}"
Body: "{'from_state': 'STOPPED', 'processname': 'event', 'tries': '0', 'groupname': 'event'}"
READY
as you see, i cannot receive the sample process event notification, although i use the comand supervisorctl restart sample
guys, any idea?
Related: #252
@mnaberez thx. but this issue is published on 2 Jul 2013, so can any idea solve this?
holy shit, now i know the reason why i cannot recevie the event. According the protocol, you cannot write other data to the stdout except READY,RESULT and so on...
supervisord will now halt with an error message if redirect_stderr=true is set in an [eventlistener:x] section. This was committed in 4420af41f34ef183e857d372e1a22af641de3149 and will be released in Supervisor 3.2.
Most helpful comment
holy shit, now i know the reason why i cannot recevie the event. According the protocol, you cannot write other data to the stdout except READY,RESULT and so on...