Skip to content

Instantly share code, notes, and snippets.

@nkwhr
Created December 11, 2014 09:51
Show Gist options
  • Save nkwhr/20e5147d931c0b6fdbad to your computer and use it in GitHub Desktop.
Save nkwhr/20e5147d931c0b6fdbad to your computer and use it in GitHub Desktop.
#!/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