#!/bin/bash # ASTERISK RESTART SCRIPT # MATT GIBSON (C) 2004 # LICENSE: BSD LICENSE # BUGS: # # - if you start the script when no process is running, but there is a pid file, it'll error out # you'll have to delete $PIDFILE and $CTLFILE # # - doesn't work on fedora for some reason *coughbecause it has a crond specific to redhat that breaks conventionscough* # TODO: # # - should it be using stop graceful instead of stop now? or configurable? # - add 'start/stop/restart' cli functions # - clean up the code # - fix it for fedora # - make it non root with a -u switch # INSTALLATION: # # cp restart_asterisk.sh /usr/sbin # chown root.bin /usr/sbin/restart_asterisk.sh (or wheel or whatever, i run it as root) # chmod +x /usr/sbin/restart_asterisk # then add to cron %crontab -e # # this is to stop and start asterisk daily at 4:20am # 20 4 * * * /usr/sbin/restart_asterisk.sh | mail root # SCRIPT BEGINS HERE # Variables # user settings SU="/bin/su" SUUSER="asterisk" USEROPT="-c /usr/sbin/safe_asterisk" # asterisk specific SAFEAST="/usr/sbin/safe_asterisk" ASTERISK="/usr/sbin/asterisk" PIDFILE="/var/run/asterisk/asterisk.pid" CTLFILE="/var/run/asterisk/asterisk.ctl" # nothing to edit here.. PATH="/bin:/sbin:/usr/bin:/usr/sbin" if [ -f $SAFEAST -a -x !$SAFEAST ]; then echo echo "no asterisk to be run ... wussup" exit 1 fi # if the physical file exists #checks for asterisk executable permissions if [ -f $ASTERISK -a -x $ASTERISK ]; then #check for pidfile existence if [ -f $PIDFILE ]; then echo echo -n "stopping and restarting asterisk:" # stop asterisk # figure out why that can't be a variable.. $ASTERISK -rx "stop now" # make sure the pidfile disappears while [ -f $PIDFILE ]; do wait done # add something here to make sure that it disappears # if it doesn't, kill file, and restart away # start asterisk $SU $SUUSER $USEROPT echo -n " successfull" echo exit 0 else $SU $SUUSER $USEROPT echo echo -n "starting asterisk:" echo -n " successfull" echo exit 0 fi else echo "no asterisk executable or executable not executable... fix things" exit 1 fi