我已经看过一些较旧的帖子,但没有回复。希望知道解决方案的人可以提供帮助
如果一个supervisord进程组有一个成员关闭,是否可以重新启动该组中的所有成员?
或者我可能会使一个EventListener重新启动该组,但我希望从supervisord获得更优雅的解决方案。
谢谢!
答案 0 :(得分:2)
作为临时解决方案,可以执行以下操作
将以下内容添加到您的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)。