#!/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 # 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-a.sh /usr/sbin # chown root.bin /usr/sbin/restart-a.sh (or wheel or whatever, i run it as root) # chmod +x /usr/sbin/restart-a.sh # then add to cron %crontab -e # # this is to stop and start asterisk daily at 4:20am # 20 4 * * * /usr/sbin/restart-a.sh | mail root # SCRIPT BEGINS HERE # Variables # user settings SUUSER="asterisk" SU="/bin/su $SUUSER -c" USEROPT="/usr/sbin/asterisk -vvv &" #STOPNOW="-rx \\\\"stop now\\\\"" # 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 !$ASTERISK -o -x !$ASTERISK ]; 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 wait # add something here to make sure that it disappears # if it doesn't, kill file, and restart away # start asterisk $SU \\"$USEROPT\\" echo -n " successfull" echo exit 0 else $SU \\"$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