Solusi 1:
Saya menyelesaikan masalah dengan 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
bunuh.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**
Juga manajemen proses artikel yang bagus dalam wadah buruh pelabuhan
Solusi 2:
Ini adalah versi yang sedikit lebih ramping yang menggunakan skrip shell alih-alih skrip python, dan juga mencakup beberapa layanan, mematikan seluruh supervisor jika gagal.
supervisord.conf$ cat /etc/supervisord.conf
[supervisord]
nodaemon=true
loglevel=debug
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor
[program:service1]
command=/usr/sbin/service1
user=someone
autostart=true
autorestart=true
startsecs=30
process_name=service1
[program:service2]
command=/usr/sbin/service2
user=root
autostart=true
autorestart=true
startsecs=30
process_name=service2
[eventlistener:processes]
command=stop-supervisor.sh
events=PROCESS_STATE_STOPPED, PROCESS_STATE_EXITED, PROCESS_STATE_FATAL
stop-supervisor.sh $ cat stop-supervisor.sh
#!/bin/bash
printf "READY\n";
while read line; do
echo "Processing Event: $line" >&2;
kill -3 $(cat "/var/run/supervisord.pid")
done < /dev/stdin
Referensi
- Manajemen Proses di Docker Containers
- Membunuh penyelia jika ada proses turunannya yang gagal
Bagaimana cara mengingat perintah tertentu dari riwayat perintah, tanpa menjalankannya
Bagaimana cara zip file dengan batas ukuran?