当一个进程 crashes/is 被杀死时,Supervisord 重启组
Supervisord restart group when one process crashes/is killed
我看到一些较早的帖子问过这个但没有回复。希望知道解决办法的人能帮忙
如果一个 supervisord 进程组有一个成员宕机,是否可以重新启动该组中的所有成员?
或者我可以制作一个 EventListener 来重新启动组,但我希望 supervisord 提供更优雅的解决方案。
谢谢!
作为临时解决方案,可以执行以下操作
将以下内容添加到您的 conf 文件中:
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
; Event listener, on any kid going down, restart all the children
[eventlistener:good_listener]
command=python /path/to/python_script.py
events=PROCESS_STATE
然后脚本:
#!/usr/bin/python
import sys
from supervisor.childutils import listener
from subprocess import call
def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()
def main():
while 1:
cmd_msg, cmd_body = listener.wait(sys.stdin, sys.
if 'eventname' in cmd_msg:
if cmd_msg['eventname'] == 'PROCESS_STATE_EXITED':
write_stderr('Process has quit\n')
call(["supervisorctl", "restart", "all"])
listener.ok(sys.stdout)
if __name__ == '__main__':
main()
这会做你想做的事,但这不是最好的做事方式 (imo)。
我看到一些较早的帖子问过这个但没有回复。希望知道解决办法的人能帮忙
如果一个 supervisord 进程组有一个成员宕机,是否可以重新启动该组中的所有成员?
或者我可以制作一个 EventListener 来重新启动组,但我希望 supervisord 提供更优雅的解决方案。
谢谢!
作为临时解决方案,可以执行以下操作
将以下内容添加到您的 conf 文件中:
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
; Event listener, on any kid going down, restart all the children
[eventlistener:good_listener]
command=python /path/to/python_script.py
events=PROCESS_STATE
然后脚本:
#!/usr/bin/python
import sys
from supervisor.childutils import listener
from subprocess import call
def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()
def main():
while 1:
cmd_msg, cmd_body = listener.wait(sys.stdin, sys.
if 'eventname' in cmd_msg:
if cmd_msg['eventname'] == 'PROCESS_STATE_EXITED':
write_stderr('Process has quit\n')
call(["supervisorctl", "restart", "all"])
listener.ok(sys.stdout)
if __name__ == '__main__':
main()
这会做你想做的事,但这不是最好的做事方式 (imo)。