Linux
如果一個以 0 結果退出,如何退出所有主管程序
我像這樣使用主管執行 docker 容器:
Dockerfile
CMD ["/run.sh"]
run.sh
#!/usr/bin/env bash exec supervisord -n
主管-serf.conf
[group:job] programs=serf,producer [program:serf] command=/start-serf-agent.sh numprocs=1 autostart=true autorestart=unexpected stopasgroup=true killasgroup=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0
start-serf-agent.sh
#!/bin/bash exec serf agent --join=serf:7946 -tag role=producer
主管-servce.conf
[program:producer] command=/start.sh numprocs=1 stopasgroup=true killasgroup=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0
start.sh
#!/bin/bash exec /producer --project=${NAME}
製片人停止後,我得到了:
producer_1 | 2016/02/29 21:59:50 [INFO] serf: EventMemberLeave: 7c4fbc80af97 172.19.0.2 producer_1 | 2016/02/29 21:59:51 INF 1 stopping producer_1 | 2016/02/29 21:59:51 INF 1 exiting router producer_1 | 2016-02-29 21:59:51,281 INFO exited: producer (exit status 0; expected) producer_1 | 2016/02/29 21:59:51 [INFO] agent: Received event: member-leave
但是 serf-agent 保持容器處於執行狀態。當生產者以狀態 0 正確完成工作時,我想停止 Docker 容器。我試圖將程序加入一個組,但似乎不起作用。伙計們,我跳過了什麼?請幫幫我!
我解決了主管事件監聽器的問題:
[program:worker] command=/start.sh priority=2 process_name=worker numprocs=1 stopasgroup=true killasgroup=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 [eventlistener:worker_exit] command=/kill.py process_name=worker events=PROCESS_STATE_EXITED
kill.py
#!/usr/bin/env python import sys import os import signal 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 1: write_stdout('READY\n') line = sys.stdin.readline() write_stdout('This line kills supervisor: ' + line); try: pidfile = open('/var/run/supervisord.pid','r') pid = int(pidfile.readline()); os.kill(pid, signal.SIGQUIT) except Exception as e: write_stdout('Could not kill supervisor: ' + e.strerror + '\n') write_stdout('RESULT 2\nOK') if __name__ == '__main__': main() import sys main issue I forgot to point to **process_name**
在 docker 容器中也很好的文章流程管理