이를 스크립트는 RabbitMQ를 백그라운드 프로세스 ('&'사용)로 시작하여 pid 파일을 업데이트/생성합니다 ('http://www.rabbitmq.com/man/rabbitmqctl.1.man.html'아래의 '대기'참조).
토끼가 시작된 후 루프가 사용되어 pid가 아직 실행 중인지 확인합니다. 토끼가 부러 지거나 수퍼 바이저 밖에서 수동으로 종료되면 스크립트가 1과 함께 종료되고 감독자가 인계합니다.
에코 >> ./rmq.txt 파일은 디버깅 목적으로 사용되며 프로덕션 환경에서 주석 처리 될 수 있습니다.이 파일을 사용하여 시작/종료/죽은 상태를 모니터링합니다.
실행중인 프로세스를 볼 수 있기 때문에 supervisord가 만족스럽고 EXIT가 깨끗한 종료를 위해 'rabbitmqctl stop'을 호출하는 stop_rmq 기능을 트리거합니다.
#!/bin/bash
# Script to manage RMQ with supervisord
# Shut down rmq
function stop_rmq {
echo "Stopping RabbitMQ..."
echo "Stopping RabbitMQ..." >> ./rmq.txt
rabbitmqctl stop
echo "RabbitMQ stopped"
echo "RabbitMQ stopped" >> ./rmq.txt
#exit 0
}
# Set up the trap
#trap stop_rabbit TERM KILL HUP INT SIGTERM SIGKILL SIGHUP SIGINT
trap stop_rmq exit
# Start rmq
echo "Starting RabbitMQ..."
echo "Starting RabbitMQ..." >> ./rmq.txt
# Start Rabbitmq in the background (causes the pid file to be updated)
# Note that the pid file location can be overridden with the rmq 'RABBITMQ_PID_FILE' variable
/usr/sbin/rabbitmq-server &
rabbitmqctl wait /var/lib/rabbitmq/mnesia/[email protected]$HOSTNAME.pid
echo "RabbitMQ Started"
echo "RabbitMQ Started" >> ./rmq.txt
while true; do
#ps $(cat /var/lib/rabbitmq/mnesia/[email protected]$HOSTNAME.pid)
ps -o pid,cmd,etime $(cat /var/lib/rabbitmq/mnesia/[email protected]$HOSTNAME.pid)
if (($? > 0)); then
echo "RabbitMQ Died"
echo "RabbitMQ Died" >> ./rmq.txt
exit 1
fi
#echo "Sleeping..."
sleep 10
done
여기 supervisord하는 스크립트에 의해 생성 된 출력입니다 :
[email protected]:/# supervisorctl tail rmq
Starting RabbitMQ...
Waiting for [email protected] ...
pid is 45220 ...
RabbitMQ 3.3.5. Copyright (C) 2007-2014 GoPivotal, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /var/log/rabbitmq/[email protected]
###### ## /var/log/rabbitmq/[email protected]
##########
Starting broker... completed with 0 plugins.
...done.
RabbitMQ Started
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:05
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:15
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:25
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:35
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:45
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 00:55
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 01:05
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 01:15
PID CMD ELAPSED
45220 /usr/lib/erlang/erts-6.1/bi 01:25
이 나를 위해 부분적으로 일했다. 최종 솔루션으로 요점을 만들었습니다. https://gist.github.com/caioariede/342a583f75467509ad42 – caio
@caio 제 솔루션이 저에게 효과적 일지 모르지만, 고맙겠습니다. –