aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-06 16:57:20 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-06 16:57:20 +0000
commitce3fb86cea36f7a6ee5504e8cc0ce0240fec0392 (patch)
treed6e879ea9e256225a2e976e9cea9158fac912357 /contrib
parent28497da2c966b13c9352ced824fb226e8f2f385c (diff)
Incorporate the ability to log output of safe_asterisk to syslog (closes issue #9882)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@81744 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'contrib')
-rw-r--r--contrib/scripts/safe_asterisk45
1 files changed, 27 insertions, 18 deletions
diff --git a/contrib/scripts/safe_asterisk b/contrib/scripts/safe_asterisk
index ed1bc5711..67bd8b4bb 100644
--- a/contrib/scripts/safe_asterisk
+++ b/contrib/scripts/safe_asterisk
@@ -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
#NOTIFY=ben@alkaloid.net # Who to notify about 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
DUMPDROP=/tmp
SLEEPSECS=4
@@ -26,15 +28,26 @@ PRIORITY=0
# set to the system's maximum files open devided by two, if not set here.
# 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
# root. if running asterisk as other users, pass that to asterisk on the command
# line.
# if we're not root, fall back to standard everything.
if [ `id -u` != 0 ]
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
PRIORITY=0
+ message "safe_asterisk was started by `id -n` (uid `id -u`)."
else
if `echo $OSTYPE | grep linux 2>&1 > /dev/null `
then
@@ -83,7 +96,7 @@ if [ "$TTY" != "" ]; then
elif [ -c /dev/vc/${TTY} ]; then
TTY=vc/${TTY}
else
- echo "Cannot find your TTY (${TTY})" >&2
+ message "Cannot find specified TTY (${TTY})"
exit 1
fi
ASTARGS="${ASTARGS} -vvvg"
@@ -92,7 +105,7 @@ if [ "$TTY" != "" ]; then
fi
fi
if [ ! -w ${DUMPDROP} ]; then
- echo "Cannot write to ${DUMPDROP}" >&2
+ message "Cannot write to ${DUMPDROP}"
exit 1
fi
@@ -126,10 +139,10 @@ run_asterisk()
nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS}
fi
EXITSTATUS=$?
- echo "Asterisk ended with exit status $EXITSTATUS"
+ message "Asterisk ended with exit status $EXITSTATUS"
if [ "$EXITSTATUS" = "0" ]; then
# Properly shutdown....
- echo "Asterisk shutdown normally."
+ message "Asterisk shutdown normally."
exit 0
elif [ $EXITSTATUS -gt 128 ]; then
let EXITSIGNAL=EXITSTATUS-128
@@ -137,6 +150,7 @@ run_asterisk()
if [ "$NOTIFY" != "" ]; then
echo "Asterisk on $MACHINE exited on signal $EXITSIGNAL. Might want to take a peek." | \
mail -s "Asterisk Died" $NOTIFY
+ message "Exited on signal $EXITSIGNAL"
fi
if [ "$EXEC" != "" ]; then
$EXEC
@@ -149,21 +163,16 @@ run_asterisk()
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."
-
- PID=`cat ${ASTPIDFILE}`
- if [ -f /tmp/core.${PID} ]; then
- mv /tmp/core.${PID} ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
- elif [ -f /tmp/core ]; then
- mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
- fi
+ message "Asterisk died with code $EXITSTATUS."
+
+ PID=`cat ${ASTPIDFILE}`
+ if [ -f /tmp/core.${PID} ]; then
+ mv /tmp/core.${PID} ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
+ elif [ -f /tmp/core ]; then
+ mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
fi
fi
- echo "Automatically restarting Asterisk."
+ message "Automatically restarting Asterisk."
sleep $SLEEPSECS
if [ $KILLALLMPG123 ]
then