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
21 OPENH323DIR=/usr/src/openh323
22 PWLIBDIR=/usr/src/pwlib
23 LD_LIBRARY_PATH=$OPENH323DIR/lib:$PWLIBDIR/lib
24 export OPENH323DIR PWLIBDIR LD_LIBRARY_PATH
26 # Source function library.
27 . /etc/rc.d/init.d/functions
30 # Don't fork when running "safely"
33 if [ "$TTY" != "" ]; then
34 if [ -c /dev/tty${TTY} ]; then
36 elif [ -c /dev/vc/${TTY} ]; then
39 echo "Cannot find your TTY (${TTY})" >&2
42 ASTARGS="${ASTARGS} -vvv"
43 if [ "$CONSOLE" != "no" ]; then
44 ASTARGS="${ASTARGS} -c"
47 if [ ! -w ${DUMPDROP} ]; then
48 echo "Cannot write to ${DUMPDROP}" >&2
53 # Let Asterisk dump core
65 if [ "$TTY" != "" ]; then
67 stty sane < /dev/${TTY}
68 asterisk ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY}
74 echo "Asterisk ended with exit status $EXITSTATUS"
75 if [ "$EXITSTATUS" = "0" ]; then
76 # Properly shutdown....
77 echo "Asterisk shutdown normally."
79 elif [ $EXITSTATUS -gt 128 ]; then
80 if [ "$EXITSTATUS" = "129" ]; then
83 elif [ "$EXITSTATUS" = "130" ]; then
86 elif [ "$EXITSTATUS" = "131" ]; then
89 elif [ "$EXITSTATUS" = "132" ]; then
91 EXITMSG="Illegal instruction"
92 elif [ "$EXITSTATUS" = "133" ]; then
95 elif [ "$EXITSTATUS" = "134" ]; then
98 elif [ "$EXITSTATUS" = "135" ]; then
101 elif [ "$EXITSTATUS" = "136" ]; then
103 EXITMSG="Floating-point exception"
104 elif [ "$EXITSTATUS" = "137" ]; then
107 elif [ "$EXITSTATUS" = "138" ]; then
109 EXITMSG="User-defined signal 1"
110 elif [ "$EXITSTATUS" = "139" ]; then
112 EXITMSG="Segmentation violation"
113 elif [ "$EXITSTATUS" = "140" ]; then
115 EXITMSG="User-defined signal 2"
116 elif [ "$EXITSTATUS" = "141" ]; then
118 EXITMSG="Broken pipe"
119 elif [ "$EXITSTATUS" = "142" ]; then
121 EXITMSG="Alarm clock"
122 elif [ "$EXITSTATUS" = "143" ]; then
124 EXITMSG="Termination"
125 elif [ "$EXITSTATUS" = "144" ]; then
127 EXITMSG="Stack fault"
129 echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG."
130 if [ "$NOTIFY" != "" ]; then
131 echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG. Might want to take a peek." | \
132 mail -s "Asterisk Died ($HOSTNAME)" $NOTIFY
134 if [ -f /tmp/core ]; then
135 mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
138 echo "Asterisk died with code $EXITSTATUS. Aborting."
139 if [ -f /tmp/core ]; then
140 mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
144 echo "Automatically restarting Asterisk."
150 gprintf "Starting asterisk: "
151 run_asterisk >/dev/null 2>&1 &
152 sleep 2 # Give it time to die
153 succeeded=`pidof asterisk|awk '{print NF}'`
154 if [ $succeeded = "0" ]; then
162 gprintf "Stopping asterisk: "
163 asterisk -r -x "stop gracefully" >/dev/null 2>&1
164 killall -9 mpg123 2>/dev/null
174 gprintf "Reloading asterisk: "
175 asterisk -r -x "reload" >/dev/null 2>&1
180 gprintf "Stopping asterisk: "
181 asterisk -r -x "stop now" >/dev/null 2>&1
190 succeeded=`pidof asterisk|awk '{print NF}'`
191 if [ $succeeded = "0" ]; then
192 echo "Asterisk is not running"
194 echo "Asterisk is currently running with $succeeded threads"
198 gprintf "*** Usage: $0 {start|stop|reload|restart|stopnow|restartnow|status}\n"