run_asterisk(){ while :; do echo ${ASTARGS} cd /tmp ${ASTSBINDIR}/asterisk ${CLIARGS} ${ASTARGS} EXITSTATUS=$? echo "Asterisk ended with exit status $EXITSTATUS" if [ "$EXITSTATUS" = "0" ]; then # Properly shutdown.... echo "Asterisk shutdown normally." exit 0 elif [ $EXITSTATUS -gt 128 ]; then let EXITSIGNAL=EXITSTATUS-128 echo "Asterisk exited on signal $EXITSIGNAL." if [ "$NOTIFY" != "" ]; then echo "Asterisk on $MACHINE exited on signal $EXITSIGNAL. Might want to take a peek." | \ mail -s "Asterisk Died" $NOTIFY fi if [ -f /tmp/core ]; then mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` & fi else if [ "${EXITSTATUS}" = "0" ]; then echo "Asterisk ended normally. Aborting." exit 0 else echo "Asterisk died with code $EXITSTATUS." if [ -f /tmp/core ]; then mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` & fi fi fi echo "Automatically restarting Asterisk." sleep 4 done}