Index: contrib/scripts/safe_asterisk =================================================================== --- contrib/scripts/safe_asterisk (revision 233774) +++ contrib/scripts/safe_asterisk (working copy) @@ -14,9 +14,9 @@ ASTSBINDIR=__ASTERISK_SBIN_DIR__ ASTPIDFILE=__ASTERISK_VARRUN_DIR__/asterisk.pid -# comment this line out to have this script _not_ kill all mpg123 processes when +# Uncomment this line out to have this script kill all mpg123 processes when # asterisk exits -KILLALLMPG123=1 +#KILLALLMPG123=1 # run asterisk with this priority PRIORITY=0 @@ -34,11 +34,11 @@ message() { echo "$1" >&2 - if [ "$SYSLOG" != "" ]; then - logger -p "${SYSLOG}.warn" -t safe_asterisk[$$] "$1" + if [ x$SYSLOG != x ]; then + logger -p "${SYSLOG}.warn" -t safe_asterisk[$$] "$1" fi - if [ "$LOGFILE" != "" ]; then - echo "safe_asterisk[$$]: $1" >> "$LOGFILE" + if [ x$LOGFILE != x ]; then + echo "safe_asterisk[$$]: $1" >> "$LOGFILE" fi } @@ -61,11 +61,11 @@ PRIORITY=0 message "safe_asterisk was started by `id -n` (uid `id -u`)." else - if `uname -s | grep Linux 2>&1 > /dev/null ` + if `uname -s | grep Linux >/dev/null 2>&1` then # maximum number of open files is set to the system maximum divided by two if # MAXFILES is not set. - if [ "$MAXFILES" = "" ] + if [ x$MAXFILES = x ] then # just check if file-max is readable if [ -r /proc/sys/fs/file-max ] @@ -74,15 +74,15 @@ fi fi SYSCTL_MAXFILES="fs.file-max" - elif `uname -s | grep Darwin 2>&1 > /dev/null ` + elif `uname -s | grep Darwin > /dev/null 2>&1` then SYSCTL_MAXFILES="kern.maxfiles" fi - if [ "$SYSMAXFILES" != "" ] + if [ x$SYSMAXFILES != x ] then - if [ "$SYSCTL_MAXFILES" != "" ] + if [ x$SYSCTL_MAXFILES != x ] then sysctl -w $SYSCTL_MAXFILES=$SYSMAXFILES fi @@ -93,7 +93,7 @@ fi -if test "x$UMASK" != "x"; then +if [ x$UMASK != x ]; then umask $UMASK fi @@ -106,7 +106,7 @@ # Don't fork when running "safely" # ASTARGS="" -if [ "$TTY" != "" ]; then +if [ x$TTY != x ]; then if [ -c /dev/tty${TTY} ]; then TTY=tty${TTY} elif [ -c /dev/vc/${TTY} ]; then @@ -146,7 +146,7 @@ { while :; do - if [ "$TTY" != "" ]; then + if [ x$TTY != x ]; then cd /tmp stty sane < /dev/${TTY} nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY} @@ -155,37 +155,37 @@ nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS} fi EXITSTATUS=$? - message "Asterisk ended with exit status $EXITSTATUS" + PID=`cat ${ASTPIDFILE}` + DATE=`date "+%Y-%m-%dT%H:%M:%S%z"` + MESSAGE="Asterisk ended with exit status $EXITSTATUS" if [ "$EXITSTATUS" = "0" ]; then # Properly shutdown.... - message "Asterisk shutdown normally." + message $MESSAGE exit 0 elif [ $EXITSTATUS -gt 128 ]; then - EXITSIGNAL=EXITSTATUS-128 + 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 + if [ x$NOTIFY != x ]; then + echo "Asterisk on $MACHINE exited on signal $EXITSIGNAL. This script will attempt to automatically restart Asterisk. A core file can be found in ${DUMPDROP}/core-${MACHINE}-${DATE}" | \ + mailx -s "Asterisk Died" $NOTIFY message "Exited on signal $EXITSIGNAL" fi - if [ "$EXEC" != "" ]; then + if [ x$EXEC != x ]; then $EXEC fi - PID=`cat ${ASTPIDFILE}` if [ -f /tmp/core.${PID} ]; then - mv /tmp/core.${PID} ${DUMPDROP}/core.`hostname`-`date -Iseconds` & + mv /tmp/core.${PID} ${DUMPDROP}/core.${MACHINE}-${DATE} & elif [ -f /tmp/core ]; then - mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` & + mv /tmp/core ${DUMPDROP}/core.${MACHINE}-${DATE} & fi else - message "Asterisk died with code $EXITSTATUS." + message $MESSAGE - PID=`cat ${ASTPIDFILE}` if [ -f /tmp/core.${PID} ]; then - mv /tmp/core.${PID} ${DUMPDROP}/core.`hostname`-`date -Iseconds` & + mv /tmp/core.${PID} ${DUMPDROP}/core.${MACHINE}-${DATE} & elif [ -f /tmp/core ]; then - mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` & + mv /tmp/core ${DUMPDROP}/core.${MACHINE}-${DATE} & fi fi message "Automatically restarting Asterisk."