Created
December 11, 2014 09:51
-
-
Save nkwhr/20e5147d931c0b6fdbad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PATH=/usr/bin:/bin:/usr/sbin:/sbin | |
export PATH | |
function pushover() { | |
curl -s -X POST \ | |
--form-string "token=$PUSHOVER_TOKEN" \ | |
--form-string "user=$PUSHOVER_USER" \ | |
--form-string "title=RabbitMQ Restart Attempted" \ | |
--form-string "message=status: $1" \ | |
--form-string "priority=1" \ | |
https://api.pushover.net/1/messages.json | |
} | |
lockfile=/tmp/.restart_rabbitmq.lock | |
mem_stat=$(rabbitmqctl status | egrep 'vm_memory_limit|total,' | cut -d',' -f2,4 | sed 's/}//g') | |
mem_total=$(echo $mem_stat | awk '{print $1}') | |
mem_limit=$(echo $mem_stat | awk '{print $2}') | |
[ $mem_total -lt $mem_limit ] && exit 0 | |
if [ -f $lockfile ] ; then | |
echo "$(date) : another process is already running" | |
exit | |
fi | |
touch $lockfile | |
echo "$(date) : restarting rabbitmq-server" | |
rabbitmqctl stop_app && sleep 1; rabbitmqctl start_app | |
retval=$? | |
echo "status: $retval" | |
pushover $retval >/dev/null | |
rm -f $lockfile | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment