3 # asterisk: Starts the asterisk service
5 # Version: @(#) /etc/rc.d/init.d/asterisk 1.0
7 # chkconfig: 2345 95 10
8 # description: Starts the asterisk service
10 # processname: asterisk
13 TTY=9 # TTY (if you want one) for Asterisk to run on
14 CONSOLE=yes # Whether or not you want a console
15 NOTIFY=root # Who to notify about crashes
18 CONFIGFILE=/etc/sysconfig/`basename $0`
22 if [ -f /usr/lib/asterisk/modules/chan_h323.so -a `grep -c ^noload=chan_h323.so /etc/asterisk/modules.conf` -eq 0 ]; then
23 OPENH323DIR=/usr/src/h323/openh323
24 PWLIBDIR=/usr/src/h323/pwlib
26 OPENH323DIR=/usr/src/oh323/openh323
27 PWLIBDIR=/usr/src/oh323/pwlib
30 # Put overrides in /etc/sysconfig/asterisk
31 [ -f $CONFIGFILE ] && . $CONFIGFILE
33 LD_LIBRARY_PATH=$OPENH323DIR/lib:$PWLIBDIR/lib
34 export OPENH323DIR PWLIBDIR LD_LIBRARY_PATH
36 # Source function library.
37 . /etc/rc.d/init.d/functions
40 # Don't fork when running "safely"
43 if [ "$TTY" != "" ]; then
44 if [ -c /dev/tty${TTY} ]; then
46 elif [ -c /dev/vc/${TTY} ]; then
49 echo "Cannot find your TTY (${TTY})" >&2
52 ASTARGS="${ASTARGS} -vvv"
53 if [ "$CONSOLE" != "no" ]; then
54 ASTARGS="${ASTARGS} -c"
57 if [ ! -w ${DUMPDROP} ]; then
58 echo "Cannot write to ${DUMPDROP}" >&2
63 # Let Asterisk dump core
71 SIGMSG=("Hangup" "Interrupt" "Quit" "Illegal instruction" "Trace trap" "IOT Trap" "Bus Error" "Floating-point exception" "Killed" "User-defined signal 1" "Segmentation violation" "User-defined signal 2" "Broken pipe" "Alarm clock" "Termination" "Stack fault")
77 if [ "$TTY" != "" ]; then
79 stty sane < /dev/${TTY}
80 asterisk ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY}
86 echo "Asterisk ended with exit status $EXITSTATUS"
87 if [ "$EXITSTATUS" = "0" ]; then
88 # Properly shutdown....
89 echo "Asterisk shutdown normally."
91 elif [ $EXITSTATUS -gt 128 ]; then
92 EXITSIGNAL=$(($EXITSTATUS - 128))
93 EXITMSG=$SIGMSG[$EXITSIGNAL]
94 echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG."
95 if [ "$NOTIFY" != "" ]; then
96 echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG. Might want to take a peek." | \
97 mail -s "Asterisk Died ($HOSTNAME)" $NOTIFY
99 if [ -f /tmp/core ]; then
100 mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
103 echo "Asterisk died with code $EXITSTATUS. Aborting."
104 if [ -f /tmp/core ]; then
105 mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
109 echo "Automatically restarting Asterisk."
115 gprintf "Starting asterisk: "
116 run_asterisk >/dev/null 2>&1 &
117 sleep 2 # Give it time to die
118 succeeded=`pidof asterisk|awk '{print NF}'`
119 if [ $succeeded = "0" ]; then
127 gprintf "Stopping asterisk: "
128 asterisk -r -x "stop gracefully" >/dev/null 2>&1
129 killall -9 mpg123 2>/dev/null
139 gprintf "Reloading asterisk: "
140 asterisk -r -x "reload" >/dev/null 2>&1
145 gprintf "Stopping asterisk: "
146 asterisk -r -x "stop now" >/dev/null 2>&1
156 service zaptel restart
161 service zaptel restart
165 succeeded=`pidof asterisk|awk '{print NF}'`
166 if [ $succeeded = "0" ]; then
167 echo "Asterisk is not running"
169 echo "Asterisk is currently running with $succeeded threads"
173 gprintf "*** Usage: $0 {start|stop[now]|reload|[full]restart[now]|status}\n"