Last active
July 13, 2016 23:11
-
-
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.
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 -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 | |
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.