linux – 如果退出0结果,如何退出所有管理程序进程

前端之家收集整理的这篇文章主要介绍了linux – 如果退出0结果,如何退出所有管理程序进程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我和这样的主管一起运行docker container:

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容器.我试图将进程加入到一个组但似乎不起作用.伙计们,我跳过了什么?请帮帮我!

解决方法

解决了supervisor eventlistener的问题:
[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**

也好文章process management in docker containers

原文链接:https://www.f2er.com/linux/399464.html

猜你在找的Linux相关文章