mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 12:16:00 +00:00
Incorporate the ability to log output of safe_asterisk to syslog (closes issue #9882)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@81744 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -6,6 +6,8 @@ TTY=9 # TTY (if you want one) for Asterisk to run on
|
|||||||
CONSOLE=yes # Whether or not you want a console
|
CONSOLE=yes # Whether or not you want a console
|
||||||
#NOTIFY=ben@alkaloid.net # Who to notify about crashes
|
#NOTIFY=ben@alkaloid.net # Who to notify about crashes
|
||||||
#EXEC=/path/to/somescript # Run this command if Asterisk crashes
|
#EXEC=/path/to/somescript # Run this command if Asterisk crashes
|
||||||
|
#LOGFILE=/path/to/logfile # Where to place the normal logfile (disabled if blank)
|
||||||
|
#SYSLOG=local0 # Which syslog facility to use (disabled if blank)
|
||||||
MACHINE=`hostname` # To specify which machine has crashed when getting the mail
|
MACHINE=`hostname` # To specify which machine has crashed when getting the mail
|
||||||
DUMPDROP=/tmp
|
DUMPDROP=/tmp
|
||||||
SLEEPSECS=4
|
SLEEPSECS=4
|
||||||
@@ -26,15 +28,26 @@ PRIORITY=0
|
|||||||
# set to the system's maximum files open devided by two, if not set here.
|
# set to the system's maximum files open devided by two, if not set here.
|
||||||
# MAXFILES=32768
|
# MAXFILES=32768
|
||||||
|
|
||||||
|
function message() {
|
||||||
|
echo "$1" >&2
|
||||||
|
if [ "$SYSLOG" != "" ]; then
|
||||||
|
logger -p "${SYSLOG}.warn" -t safe_asterisk[$$] "$1"
|
||||||
|
fi
|
||||||
|
if [ "$LOGFILE" != "" ]; then
|
||||||
|
echo "safe_asterisk[$$]: $1" >> "$LOGFILE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# since we're going to change priority and open files limits, we need to be
|
# since we're going to change priority and open files limits, we need to be
|
||||||
# root. if running asterisk as other users, pass that to asterisk on the command
|
# root. if running asterisk as other users, pass that to asterisk on the command
|
||||||
# line.
|
# line.
|
||||||
# if we're not root, fall back to standard everything.
|
# if we're not root, fall back to standard everything.
|
||||||
if [ `id -u` != 0 ]
|
if [ `id -u` != 0 ]
|
||||||
then
|
then
|
||||||
echo "Ops. I'm not root. Falling back to standard prio and file max." >&2
|
echo "Oops. I'm not root. Falling back to standard prio and file max." >&2
|
||||||
echo "This is NOT suitable for large systems." >&2
|
echo "This is NOT suitable for large systems." >&2
|
||||||
PRIORITY=0
|
PRIORITY=0
|
||||||
|
message "safe_asterisk was started by `id -n` (uid `id -u`)."
|
||||||
else
|
else
|
||||||
if `echo $OSTYPE | grep linux 2>&1 > /dev/null `
|
if `echo $OSTYPE | grep linux 2>&1 > /dev/null `
|
||||||
then
|
then
|
||||||
@@ -83,7 +96,7 @@ if [ "$TTY" != "" ]; then
|
|||||||
elif [ -c /dev/vc/${TTY} ]; then
|
elif [ -c /dev/vc/${TTY} ]; then
|
||||||
TTY=vc/${TTY}
|
TTY=vc/${TTY}
|
||||||
else
|
else
|
||||||
echo "Cannot find your TTY (${TTY})" >&2
|
message "Cannot find specified TTY (${TTY})"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
ASTARGS="${ASTARGS} -vvvg"
|
ASTARGS="${ASTARGS} -vvvg"
|
||||||
@@ -92,7 +105,7 @@ if [ "$TTY" != "" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ ! -w ${DUMPDROP} ]; then
|
if [ ! -w ${DUMPDROP} ]; then
|
||||||
echo "Cannot write to ${DUMPDROP}" >&2
|
message "Cannot write to ${DUMPDROP}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -126,10 +139,10 @@ run_asterisk()
|
|||||||
nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS}
|
nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS}
|
||||||
fi
|
fi
|
||||||
EXITSTATUS=$?
|
EXITSTATUS=$?
|
||||||
echo "Asterisk ended with exit status $EXITSTATUS"
|
message "Asterisk ended with exit status $EXITSTATUS"
|
||||||
if [ "$EXITSTATUS" = "0" ]; then
|
if [ "$EXITSTATUS" = "0" ]; then
|
||||||
# Properly shutdown....
|
# Properly shutdown....
|
||||||
echo "Asterisk shutdown normally."
|
message "Asterisk shutdown normally."
|
||||||
exit 0
|
exit 0
|
||||||
elif [ $EXITSTATUS -gt 128 ]; then
|
elif [ $EXITSTATUS -gt 128 ]; then
|
||||||
let EXITSIGNAL=EXITSTATUS-128
|
let EXITSIGNAL=EXITSTATUS-128
|
||||||
@@ -137,6 +150,7 @@ run_asterisk()
|
|||||||
if [ "$NOTIFY" != "" ]; then
|
if [ "$NOTIFY" != "" ]; then
|
||||||
echo "Asterisk on $MACHINE exited on signal $EXITSIGNAL. Might want to take a peek." | \
|
echo "Asterisk on $MACHINE exited on signal $EXITSIGNAL. Might want to take a peek." | \
|
||||||
mail -s "Asterisk Died" $NOTIFY
|
mail -s "Asterisk Died" $NOTIFY
|
||||||
|
message "Exited on signal $EXITSIGNAL"
|
||||||
fi
|
fi
|
||||||
if [ "$EXEC" != "" ]; then
|
if [ "$EXEC" != "" ]; then
|
||||||
$EXEC
|
$EXEC
|
||||||
@@ -149,11 +163,7 @@ run_asterisk()
|
|||||||
mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ "${EXITSTATUS}" = "0" ]; then
|
message "Asterisk died with code $EXITSTATUS."
|
||||||
echo "Asterisk ended normally. Aborting."
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo "Asterisk died with code $EXITSTATUS."
|
|
||||||
|
|
||||||
PID=`cat ${ASTPIDFILE}`
|
PID=`cat ${ASTPIDFILE}`
|
||||||
if [ -f /tmp/core.${PID} ]; then
|
if [ -f /tmp/core.${PID} ]; then
|
||||||
@@ -162,8 +172,7 @@ run_asterisk()
|
|||||||
mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
message "Automatically restarting Asterisk."
|
||||||
echo "Automatically restarting Asterisk."
|
|
||||||
sleep $SLEEPSECS
|
sleep $SLEEPSECS
|
||||||
if [ $KILLALLMPG123 ]
|
if [ $KILLALLMPG123 ]
|
||||||
then
|
then
|
||||||
|
Reference in New Issue
Block a user