4 # Mon Jun 04 2007 IƱaki Baz Castillo <ibc@in.ilimit.es>
5 # - Eliminated SAFE_ASTERISK since it doesn't work as LSB script (it could require a independent "safe_asterisk" init script).
6 # - Load and use the standar "/lib/lsb/init-functions".
7 # - Added "--oknodo" to "start-stop-daemon" for compatibility with LSB:
8 # http://www.linux-foundation.org/spec/refspecs/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
10 # Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net>
11 # - Reversed behavior of LD_ASSUME_KERNEL=2.4.1
12 # - Added detailed failure messages
14 # Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
15 # - Added test for safe_asterisk
16 # - Changed "stop gracefully" to "stop now"
17 # - Added support for -U and -G command line options
18 # - Modified "reload" to call asterisk -rx 'reload'
20 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
23 # Full path to asterisk binary
24 DAEMON=__ASTERISK_SBIN_DIR__/asterisk
25 ASTVARRUNDIR=__ASTERISK_VARRUN_DIR__
26 ASTETCDIR=__ASTERISK_ETC_DIR__
31 # Required-Start: $local_fs
32 # Required-Stop: $local_fs
33 # Should-Start: dahdi mysql postgresql
35 # Default-Start: 2 3 4 5
37 # Short-Description: Asterisk PBX
38 # Description: the Asterisk Open Source PBX
43 if ! [ -x $DAEMON ] ; then
44 echo "ERROR: $DAEMON not found"
48 if ! [ -d $ASTETCDIR ] ; then
49 echo "ERROR: $ASTETCDIR directory not found"
53 # Use the LSB standar functions for services management
54 . /lib/lsb/init-functions
56 # Allow configuration overrides in /etc/default/asterisk
58 if [ "$CONFIG0" = "" ]; then
59 CONFIGFILE=/etc/default/`basename $0`
61 CONFIGFILE=/etc/default/`basename $CONFIG0`
63 [ -r $CONFIGFILE ] && . $CONFIGFILE
67 # Check if Asterisk is already running. If it is, then bug out, because
68 # starting up Asterisk when Asterisk is already running is very bad.
69 VERSION=`${DAEMON} -rx 'core show version' || ${TRUE}`
70 if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
71 echo "Asterisk is already running. $0 will exit now."
75 log_begin_msg "Starting $DESC: $NAME"
76 if [ ! -d $ASTVARRUNDIR ]; then
77 mkdir -p $ASTVARRUNDIR
80 if [ $AST_USER ] ; then
81 ASTARGS="-U $AST_USER"
82 chown $AST_USER $ASTVARRUNDIR
84 if [ $AST_GROUP ] ; then
85 ASTARGS="$ASTARGS -G $AST_GROUP"
86 chgrp $AST_GROUP $ASTVARRUNDIR
89 ASTARGS="$ASTARGS -C \"$ALTCONF\""
91 if [ "x$COREDUMP" = "xyes" ]; then
94 if [ "0$MAXLOAD" -gt "0" ]; then
95 ASTARGS="$ASTARGS -L $MAXLOAD"
97 if [ "0$MAXCALLS" -gt "0" ]; then
98 ASTARGS="$ASTARGS -M $MAXCALLS"
100 if [ "0$VERBOSITY" -gt "0" ]; then
101 for i in `seq 1 $VERBOSITY`; do
102 ASTARGS="$ASTARGS -v"
105 if [ "x$INTERNALTIMING" = "xyes" ]; then
106 ASTARGS="$ASTARGS -I"
108 if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
109 ASTARGS="$ASTARGS -t"
111 # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already running (as LSB expects):
112 if test "x$COLOR" = "xyes" ; then
114 start-stop-daemon --start --oknodo --background --exec $DAEMON -- $ASTARGS -c
116 start-stop-daemon --start --oknodo --exec $DAEMON -- $ASTARGS
121 log_begin_msg "Stopping $DESC: $NAME"
122 # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already stopped (as LSB expects):
123 start-stop-daemon --stop --oknodo --exec $DAEMON
127 echo "Reloading $DESC configuration files."
128 $DAEMON -rx 'module reload' > /dev/null 2> /dev/null
130 restart|force-reload)
132 sleep 2 # It needs some time to really be stopped.
134 # "restart|force-reload" starts Asterisk and returns 0 even if Asterisk was stopped (as LSB expects).
138 echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2