shell代码:
- #!/bin/bash
- # Add the following line to your crontab
- #*/5 * * * * root /root/bin/asterisk-watchdog
- LOCKFILE=/tmp/asterisk-watchdog-disable
- SOCKETFILE=/var/run/asterisk.ctl
- PIDFILE=/var/run/asterisk.pid
- ADMINEMAIL=admin@bogus.mail
- if [ "$1" = "test" ]; then
- MESSAGE="asterisk-watchdog notification: test notification on `hostname` at `date`"
- else
- [ -f $LOCKFILE ] && exit 0 # check to see if watchdog is temporarily disabled
- [ -S $SOCKETFILE -a -f $PIDFILE ] && exit 0 # check for existence of asterisk ctl socket
- /etc/init.d/asterisk start # restart asterisk if the socket is not there
- sleep 5 # give asterisk some time to stabilize of die
- if [ -S $SOCKETFILE ]; then # check again, notify if its up or down
- MESSAGE="asterisk-watchdog notification: asterisk restarted on `hostname` at `date`"
- else
- MESSAGE="asterisk-watchdog notification: asterisk is down and not recovered on `hostname` at `date`"
- fi
- fi
- echo "Sending the following message to $ADMINEMAIL:"
- echo "$MESSAGE"
- echo "$MESSAGE" | mail $ADMINEMAIL -s "$MESSAGE"
安装脚本:
- #!/bin/bash
- mkdir /root/bin/
- cd /root/bin
- if [ -f asterisk-watchdog ]; then
- echo "/root/bin/asterisk-watchdog already exists"
- exit 1
- fi
- wget http://www.bluecrow.net/files/asterisk/asterisk-watchdog/asterisk-watchdog http://www.bluecrow.net/files/asterisk/asterisk-watchdog/asterisk-watchdog-crontab http://www.bluecrow.net/files/asterisk/asterisk-watchdog/asterisk-watchdog-disable http://www.bluecrow.net/files/asterisk/asterisk-watchdog/asterisk-watchdog-enable
- cat asterisk-watchdog-crontab >> /etc/crontab
- rm -f asterisk-watchdog-crontab
- /etc/init.d/crond reload
- chmod 755 asterisk-watchdog*
- ./asterisk-watchdog-enable
- echo "asterisk-watchdog has been installed into crond and enabled"