我正在使用Supervisor's events framework訂閱來自Supervisor管理的進程的事件。如何爲所有進程訂閱PROCESS_STATE_RUNNING事件
我的事件監聽器,processlistener.py
,看起來是這樣的:
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()
在我supervisord.conf
,我有:
[program:theprogramname]
command=/bin/cat ; the program (relative uses PATH, can take args)
process_name=%(program_name)s_%(process_num)s ; process_name expr (default %(program_name)s)
numprocs=1 ; number of processes copies to start (def 1)
[eventlistener:theeventlistenername]
command=python processlistener.py ; the program (relative uses PATH, can take args)
process_name=%(program_name)s_%(process_num)s ; process_name expr (default %(program_name)s)
numprocs=1 ; number of processes copies to start (def 1)
events=PROCESS_STATE_RUNNING ; event notif. types to subscribe to (req'd)
有了這個配置,我期待我的事件監聽器通知每當由主管管理的進程進入RUNNING
狀態。然而,這種情況並非如此。當我用SIGINT
信號殺死theprogramname
時,Supervisor將重新啓動該進程,但我的監聽程序未收到通知。
我是否缺少額外的配置以實現我想要的功能?