Index: safe_asterisk =================================================================== --- safe_asterisk (revision 8050) +++ safe_asterisk (working copy) @@ -6,6 +6,27 @@ MACHINE=`hostname` # To specify which machine has crashed when getting the mail DUMPDROP=/tmp ASTSBINDIR=__ASTERISK_SBIN_DIR__ + +# run asterisk with this priority +PRIORITY=-19 + +# set max files open with ulimit. On linux systems, this will be automatically +# set to the system's maximum files open devided by two, if not set here. +# MAXFILES=32768 + +# maxiimum number of open files is set to the system maximum divided by two. +if [ "$MAXFILES" = "" ] +then + if `echo $OSTYPE | grep linux 2>&1 > /dev/null ` + then + # just check if file-max is readable + if [ -r /proc/sys/fs/file-max ] + then + MAXFILES=$(( `cat /proc/sys/fs/file-max` / 2 )) + fi + fi +fi + # # Don't fork when running "safely" # @@ -34,6 +55,9 @@ # ulimit -c unlimited +# set the process's filemax to whatever set above +ulimit -n $MAXFILES + #launch_asterisk() #{ #} @@ -45,10 +69,10 @@ if [ "$TTY" != "" ]; then cd /tmp stty sane < /dev/${TTY} - ${ASTSBINDIR}/asterisk ${CLIARGS} ${ASTARGS} >& /dev/${TTY} < /dev/${TTY} + nice -n $PRIORITY ${ASTSBINDIR}/asterisk ${CLIARGS} ${ASTARGS} >& /dev/${TTY} < /dev/${TTY} else cd /tmp - ${ASTSBINDIR}/asterisk ${CLIARGS} ${ASTARGS} + nice -n $PRIORITY ${ASTSBINDIR}/asterisk ${CLIARGS} ${ASTARGS} fi EXITSTATUS=$? echo "Asterisk ended with exit status $EXITSTATUS" @@ -63,7 +87,7 @@ 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 + if [ -f /tmp/core ]; then mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` & fi else @@ -72,7 +96,7 @@ exit 0 else echo "Asterisk died with code $EXITSTATUS." - if [ -f /tmp/core ]; then + if [ -f /tmp/core ]; then mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` & fi fi