mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-19 03:07:59 +00:00
Portability and other fixes for the safe_asterisk script
(closes issue #16416) Reported by: bklang Patches: safe_asterisk-compat-1.patch uploaded by bklang (license 919) 20100106__issue16416__trunk.diff.txt uploaded by tilghman (license 14) Tested by: bklang git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@239307 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -29,7 +29,7 @@ PRIORITY=0
|
|||||||
# Check if Asterisk is already running. If it is, then bug out, because
|
# Check if Asterisk is already running. If it is, then bug out, because
|
||||||
# starting safe_asterisk when Asterisk is running is very bad.
|
# starting safe_asterisk when Asterisk is running is very bad.
|
||||||
VERSION=`${ASTSBINDIR}/asterisk -rx 'core show version'`
|
VERSION=`${ASTSBINDIR}/asterisk -rx 'core show version'`
|
||||||
if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
|
if test "`echo $VERSION | cut -c 1-8`" = "Asterisk" ; then
|
||||||
echo "Asterisk is already running. $0 will exit now."
|
echo "Asterisk is already running. $0 will exit now."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -38,35 +38,28 @@ fi
|
|||||||
# 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 test `id -u` != 0 ; then
|
||||||
then
|
|
||||||
echo "Oops. 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
|
||||||
else
|
else
|
||||||
if `uname -s | grep Linux 2>&1 > /dev/null `
|
if `uname -s | grep Linux >/dev/null 2>&1`; then
|
||||||
then
|
|
||||||
# maximum number of open files is set to the system maximum divided by two if
|
# maximum number of open files is set to the system maximum divided by two if
|
||||||
# MAXFILES is not set.
|
# MAXFILES is not set.
|
||||||
if [ "$MAXFILES" = "" ]
|
if test "x$MAXFILES" = "x" ; then
|
||||||
then
|
|
||||||
# just check if file-max is readable
|
# just check if file-max is readable
|
||||||
if [ -r /proc/sys/fs/file-max ]
|
if test -r /proc/sys/fs/file-max ; then
|
||||||
then
|
|
||||||
MAXFILES=$(( `cat /proc/sys/fs/file-max` / 2 ))
|
MAXFILES=$(( `cat /proc/sys/fs/file-max` / 2 ))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
SYSCTL_MAXFILES="fs.file-max"
|
SYSCTL_MAXFILES="fs.file-max"
|
||||||
elif `uname -s | grep Darwin 2>&1 > /dev/null `
|
elif `uname -s | grep Darwin /dev/null 2>&1`; then
|
||||||
then
|
|
||||||
SYSCTL_MAXFILES="kern.maxfiles"
|
SYSCTL_MAXFILES="kern.maxfiles"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ "$SYSMAXFILES" != "" ]
|
if test "x$SYSMAXFILES" != "x"; then
|
||||||
then
|
if test "x$SYSCTL_MAXFILES" != "x"; then
|
||||||
if [ "$SYSCTL_MAXFILES" != "" ]
|
|
||||||
then
|
|
||||||
sysctl -w $SYSCTL_MAXFILES=$SYSMAXFILES
|
sysctl -w $SYSCTL_MAXFILES=$SYSMAXFILES
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -85,21 +78,21 @@ ulimit -c unlimited
|
|||||||
# Don't fork when running "safely"
|
# Don't fork when running "safely"
|
||||||
#
|
#
|
||||||
ASTARGS=""
|
ASTARGS=""
|
||||||
if [ "$TTY" != "" ]; then
|
if test "x$TTY" != "x" ; then
|
||||||
if [ -c /dev/tty${TTY} ]; then
|
if test -c /dev/tty${TTY} ; then
|
||||||
TTY=tty${TTY}
|
TTY=tty${TTY}
|
||||||
elif [ -c /dev/vc/${TTY} ]; then
|
elif test -c /dev/vc/${TTY} ; then
|
||||||
TTY=vc/${TTY}
|
TTY=vc/${TTY}
|
||||||
else
|
else
|
||||||
echo "Cannot find your TTY (${TTY})" >&2
|
echo "Cannot find your TTY (${TTY})" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
ASTARGS="${ASTARGS} -vvvg"
|
ASTARGS="${ASTARGS} -vvvg"
|
||||||
if [ "$CONSOLE" != "no" ]; then
|
if test "x$CONSOLE" != "xno" ; then
|
||||||
ASTARGS="${ASTARGS} -c"
|
ASTARGS="${ASTARGS} -c"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ ! -w ${DUMPDROP} ]; then
|
if test ! -w "${DUMPDROP}" ; then
|
||||||
echo "Cannot write to ${DUMPDROP}" >&2
|
echo "Cannot write to ${DUMPDROP}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -113,9 +106,9 @@ trap '' PIPE
|
|||||||
# Run scripts to set any environment variables or do any other system-specific setup needed
|
# Run scripts to set any environment variables or do any other system-specific setup needed
|
||||||
#
|
#
|
||||||
|
|
||||||
if [ -d /etc/asterisk/startup.d ]; then
|
if test -d /etc/asterisk/startup.d ; then
|
||||||
for script in /etc/asterisk/startup.d/*.sh; do
|
for script in /etc/asterisk/startup.d/*.sh; do
|
||||||
if [ -x ${script} ]; then
|
if test -r ${script} ; then
|
||||||
. ${script}
|
. ${script}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -125,7 +118,7 @@ run_asterisk()
|
|||||||
{
|
{
|
||||||
while :; do
|
while :; do
|
||||||
|
|
||||||
if [ "$TTY" != "" ]; then
|
if test "x$TTY" != "x" ; then
|
||||||
cd /tmp
|
cd /tmp
|
||||||
stty sane < /dev/${TTY}
|
stty sane < /dev/${TTY}
|
||||||
nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS} >& /dev/${TTY} < /dev/${TTY}
|
nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS} >& /dev/${TTY} < /dev/${TTY}
|
||||||
@@ -135,41 +128,42 @@ run_asterisk()
|
|||||||
fi
|
fi
|
||||||
EXITSTATUS=$?
|
EXITSTATUS=$?
|
||||||
echo "Asterisk ended with exit status $EXITSTATUS"
|
echo "Asterisk ended with exit status $EXITSTATUS"
|
||||||
if [ "$EXITSTATUS" = "0" ]; then
|
if test "x$EXITSTATUS" = "x0" ; then
|
||||||
# Properly shutdown....
|
# Properly shutdown....
|
||||||
echo "Asterisk shutdown normally."
|
echo "Asterisk shutdown normally."
|
||||||
exit 0
|
exit 0
|
||||||
elif [ $EXITSTATUS -gt 128 ]; then
|
elif test "0$EXITSTATUS" -gt "128" ; then
|
||||||
EXITSIGNAL=EXITSTATUS-128
|
EXITSIGNAL=$(($EXITSTATUS - 128))
|
||||||
echo "Asterisk exited on signal $EXITSIGNAL."
|
echo "Asterisk exited on signal $EXITSIGNAL."
|
||||||
if [ "$NOTIFY" != "" ]; then
|
if test "x$NOTIFY" != "x" ; 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
|
||||||
fi
|
fi
|
||||||
if [ "$EXEC" != "" ]; then
|
if test "x$EXEC" != "x" ; then
|
||||||
$EXEC
|
$EXEC
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PID=`cat ${ASTPIDFILE}`
|
PID=`cat ${ASTPIDFILE}`
|
||||||
if [ -f /tmp/core.${PID} ]; then
|
DATE=`date "+%Y-%m-%dT%H:%M:%S%z"`
|
||||||
mv /tmp/core.${PID} ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
if test -f /tmp/core.${PID} ; then
|
||||||
elif [ -f /tmp/core ]; then
|
mv /tmp/core.${PID} ${DUMPDROP}/core.`hostname`-$DATE &
|
||||||
mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
elif test -f /tmp/core ; then
|
||||||
|
mv /tmp/core ${DUMPDROP}/core.`hostname`-$DATE &
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Asterisk died with code $EXITSTATUS."
|
echo "Asterisk died with code $EXITSTATUS."
|
||||||
|
|
||||||
PID=`cat ${ASTPIDFILE}`
|
PID=`cat ${ASTPIDFILE}`
|
||||||
if [ -f /tmp/core.${PID} ]; then
|
DATE=`date "+%Y-%m-%dT%H:%M:%S%z"`
|
||||||
mv /tmp/core.${PID} ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
if test -f /tmp/core.${PID} ; then
|
||||||
elif [ -f /tmp/core ]; then
|
mv /tmp/core.${PID} ${DUMPDROP}/core.`hostname`-$DATE &
|
||||||
mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
elif test -f /tmp/core ; then
|
||||||
|
mv /tmp/core ${DUMPDROP}/core.`hostname`-$DATE &
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "Automatically restarting Asterisk."
|
echo "Automatically restarting Asterisk."
|
||||||
sleep $SLEEPSECS
|
sleep $SLEEPSECS
|
||||||
if [ $KILLALLMPG123 ]
|
if test "0$KILLALLMPG123" -gt "0" ; then
|
||||||
then
|
|
||||||
killall -9 mpg123
|
killall -9 mpg123
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user