2016-07-27 88 views
0

我见过一些较旧的帖子询问这个,但没有回应。希望知道解决方案的人可以帮助Supervisord重启组,当一个进程崩溃/被杀死

如果supervisord进程组有一个成员关闭,是否可以重新启动该组中的所有成员?

或者我可以让一个EventListener重新启动组,但我希望从supervisord获得更优雅的解决方案。

谢谢!

回答

1

作为一个临时解决方案,一个可以做以下

以下内容添加到您的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)。