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 if [ 0`readlink $0` = "0" ]; then
19 CONFIGFILE=/etc/sysconfig/`basename $0`
22 CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
27 if [ -f /usr/lib/asterisk/modules/chan_h323.so -a `grep -c ^noload=chan_h323.so /etc/asterisk/modules.conf` -eq 0 ]; then
28 OPENH323DIR=/usr/src/h323/openh323
29 PWLIBDIR=/usr/src/h323/pwlib
31 OPENH323DIR=/usr/src/oh323/openh323
32 PWLIBDIR=/usr/src/oh323/pwlib
35 # Put overrides in /etc/sysconfig/asterisk
36 [ -f $CONFIGFILE ] && . $CONFIGFILE
38 LD_LIBRARY_PATH=$OPENH323DIR/lib:$PWLIBDIR/lib
39 export OPENH323DIR PWLIBDIR LD_LIBRARY_PATH
41 # Source function library.
42 . /etc/rc.d/init.d/functions
45 # Don't fork when running "safely"
48 if [ "$TTY" != "" ]; then
49 if [ -c /dev/tty${TTY} ]; then
51 elif [ -c /dev/vc/${TTY} ]; then
54 echo "Cannot find your TTY (${TTY})" >&2
57 ASTARGS="${ASTARGS} -vvv"
58 if [ "$CONSOLE" != "no" ]; then
59 ASTARGS="${ASTARGS} -c"
62 if [ ! -w ${DUMPDROP} ]; then
63 echo "Cannot write to ${DUMPDROP}" >&2
68 # Let Asterisk dump core
76 SIGMSG=("None", "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")
82 if [ "$TTY" != "" ]; then
84 stty sane < /dev/${TTY}
85 asterisk ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY}
91 echo "Asterisk ended with exit status $EXITSTATUS"
92 if [ "$EXITSTATUS" = "0" ]; then
93 # Properly shutdown....
94 echo "Asterisk shutdown normally."
96 elif [ $EXITSTATUS -gt 128 ]; then
97 EXITSIGNAL=$(($EXITSTATUS - 128))
98 EXITMSG=${SIGMSG[$EXITSIGNAL]}
99 echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG."
100 if [ "$NOTIFY" != "" ]; then
101 echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG. Might want to take a peek." | \
102 mail -s "Asterisk Died ($HOSTNAME)" $NOTIFY
104 if [ -f /tmp/core ]; then
105 mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
108 echo "Asterisk died with code $EXITSTATUS. Aborting."
109 if [ -f /tmp/core ]; then
110 mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
114 echo "Automatically restarting Asterisk."
120 gprintf "Starting asterisk: "
121 run_asterisk >/dev/null 2>&1 &
122 sleep 2 # Give it time to die
123 succeeded=`pidof asterisk|awk '{print NF}'`
124 if [ $succeeded = "0" ]; then
132 gprintf "Stopping asterisk: "
133 asterisk -r -x "stop gracefully" >/dev/null 2>&1
134 killall -9 mpg123 2>/dev/null
144 gprintf "Reloading asterisk: "
145 asterisk -r -x "reload" >/dev/null 2>&1
150 gprintf "Stopping asterisk: "
151 asterisk -r -x "stop now" >/dev/null 2>&1
161 service zaptel restart
166 service zaptel restart
170 succeeded=`pidof asterisk|awk '{print NF}'`
171 if [ $succeeded = "0" ]; then
172 echo "Asterisk is not running"
174 echo "Asterisk is currently running with $succeeded threads"
178 gprintf "*** Usage: $0 {start|stop[now]|reload|[full]restart[now]|status}\n"