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
15 TTY=9 # TTY (if you want one) for Asterisk to run on
16 CONSOLE=yes # Whether or not you want a console
17 NOTIFY=root # Who to notify about crashes
22 if [ 0`readlink $0` = "0" ]; then
23 CONFIGFILE=/etc/sysconfig/`basename $0`
26 CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
31 if [ -f /usr/lib/asterisk/modules/chan_h323.so -a `grep -c ^noload=chan_h323.so /etc/asterisk/modules.conf` -eq 0 ]; then
32 OPENH323DIR=/usr/src/h323/openh323
33 PWLIBDIR=/usr/src/h323/pwlib
35 OPENH323DIR=/usr/src/oh323/openh323
36 PWLIBDIR=/usr/src/oh323/pwlib
39 # Put overrides in /etc/sysconfig/asterisk
40 [ -r $CONFIGFILE ] && . $CONFIGFILE
42 LD_LIBRARY_PATH=$OPENH323DIR/lib:$PWLIBDIR/lib
43 export OPENH323DIR PWLIBDIR LD_LIBRARY_PATH
45 # Source function library.
46 . /etc/rc.d/init.d/functions
49 # Don't fork when running "safely"
52 if [ "$TTY" != "" ]; then
53 if [ -c /dev/tty${TTY} ]; then
55 elif [ -c /dev/vc/${TTY} ]; then
58 echo "Cannot find your TTY (${TTY})" >&2
61 ASTARGS="${ASTARGS} -vvv"
62 if [ "$CONSOLE" != "no" ]; then
63 ASTARGS="${ASTARGS} -c"
66 if [ ! -w ${DUMPDROP} ]; then
67 echo "Cannot write to ${DUMPDROP}" >&2
72 # Let Asterisk dump core
80 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")
86 if [ "$TTY" != "" ]; then
88 stty sane < /dev/${TTY}
89 asterisk ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY}
95 echo "Asterisk ended with exit status $EXITSTATUS"
96 if [ "$EXITSTATUS" = "0" ]; then
97 # Properly shutdown....
98 echo "Asterisk shutdown normally."
100 elif [ $EXITSTATUS -gt 128 ]; then
101 EXITSIGNAL=$(($EXITSTATUS - 128))
102 EXITMSG=${SIGMSG[$EXITSIGNAL]}
103 echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG."
104 if [ "$NOTIFY" != "" ]; then
105 echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG. Might want to take a peek." | \
106 mail -s "Asterisk Died ($HOSTNAME)" $NOTIFY
108 if [ -f /tmp/core ]; then
109 mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
112 echo "Asterisk died with code $EXITSTATUS. Aborting."
113 if [ -f /tmp/core ]; then
114 mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
118 echo "Automatically restarting Asterisk."
124 # Check if Asterisk is already running. If it is, then bug out, because
125 # starting Asterisk when Asterisk is already running is very bad.
126 VERSION=`${ASTSBINDIR}/asterisk -rx 'core show version'`
127 if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
128 echo "Asterisk is already running. $0 will exit now."
132 gprintf "Starting asterisk: "
133 run_asterisk >/dev/null 2>&1 &
134 sleep 2 # Give it time to die
135 succeeded=`pidof asterisk|awk '{print NF}'`
136 if [ $succeeded = "0" ]; then
144 gprintf "Stopping asterisk: "
145 asterisk -r -x "core stop gracefully" >/dev/null 2>&1
146 killall -9 mpg123 2>/dev/null
156 gprintf "Reloading asterisk: "
157 asterisk -r -x "module reload" >/dev/null 2>&1
162 gprintf "Stopping asterisk: "
163 asterisk -r -x "core stop now" >/dev/null 2>&1
173 service dahdi restart
178 service dahdi restart
182 succeeded=`pidof asterisk|awk '{print NF}'`
183 if [ $succeeded = "0" ]; then
184 echo "Asterisk is not running"
186 echo "Asterisk is currently running with $succeeded threads"
190 gprintf "*** Usage: $0 {start|stop[now]|reload|[full]restart[now]|status}\n"