Questo lo script avvia RabbitMQ come processo in background (utilizzando '&') che provoca l'aggiornamento/la creazione di un file PID (vedere 'attendere' sotto http://www.rabbitmq.com/man/rabbitmqctl.1.man.html).
Dopo l'avvio di coniglio, viene utilizzato un ciclo per verificare che il pid sia ancora in esecuzione. Se il coniglio si blocca o viene spento manualmente (fuori da supervisord), lo script uscirà con 1 e supervisord prenderà il sopravvento.
L'eco >> ./rmq.il file txt è disponibile per scopi di debug e può essere commentato in produzione (l'ho usato per monitorare lo stato di avvio/arresto/morte).
supervisord è felice perché può vedere un processo in esecuzione e un EXIT attiverà la funzione stop_rmq che chiama 'rabbitmqctl stop' per un arresto pulito.
#!/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
Ecco l'output generato dallo script di 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
fonte
2014-08-22 14:39:27
questo ha funzionato in parte per me. Ho creato una sintesi con la mia soluzione finale: https://gist.github.com/caioariede/342a583f75467509ad42 – caio
@caio sebbene la mia soluzione funzioni per me, dovrei ringraziarti per la tua. –