Skip to content

Instantly share code, notes, and snippets.

@tolitski
Last active July 13, 2016 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tolitski/5e302d31f4f56b35bf68615a65366bf9 to your computer and use it in GitHub Desktop.
Save tolitski/5e302d31f4f56b35bf68615a65366bf9 to your computer and use it in GitHub Desktop.
This is a short script to monitor an allstar node and will restart if for some reason asterisk crashes.
#!/bin/bash -x
# Thanks for justin campbell for his original code.
DIR=/tmp/watchdog
#replace this with your node number
NODE=41787
# Create dir if it doesn't exist
if [ ! -d $DIR ]; then
mkdir $DIR
fi
cd $DIR
# Save current registration times
/usr/sbin/asterisk -rx "iax2 show registry" | grep $NODE | cut -b 74- > current
# If previous exists, compare current to previous
if [ -f previous ]; then
cmp current previous
# If they match, restart Asterisk
if [ $? == 0 ]; then
/etc/init.d/asterisk restart
fi
fi
# delete the previous file
rm -f previous
mv current previous
# Add allstar_watchdog.sh to cron, make sure you create the watchdog script in the /etc/asterisk/folder
if ! grep -q "0,10,20,30,40,50 * * * * /etc/asterisk/allstar_watchdog.sh" /var/spool/cron/root; then
echo "0,10,20,30,40,50 * * * * /etc/asterisk/allstar_watchdog.sh">>/var/spool/cron/root
fi
@tolitski
Copy link
Author

Before using this, make sure you have entries that appear when you execute "iax2 show registry" and that your node will show up. Otherwise, your server will keep rebooting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment