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 standard "/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: $network $syslog $named $local_fs $remote_fs
32 # Required-Stop: $network $syslog $named $local_fs $remote_fs
33 # Should-Start: dahdi misdn lcr wanrouter mysql postgresql
34 # Should-Stop: dahdi misdn lcr wanrouter 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 standard functions for services management
54 . /lib/lsb/init-functions
56 # Allow configuration overrides in /etc/default/asterisk
57 CONFIG0=`readlink $0 || :` # readlink returns 1 when something isn't a symlink
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' 2>/dev/null || ${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
79 if [ $AST_USER ] ; then
80 ASTARGS="-U $AST_USER"
81 chown $AST_USER $ASTVARRUNDIR
83 if [ $AST_GROUP ] ; then
84 ASTARGS="$ASTARGS -G $AST_GROUP"
85 chgrp $AST_GROUP $ASTVARRUNDIR
88 ASTARGS="$ASTARGS -C $ALTCONF"
90 if [ "x$COREDUMP" = "xyes" ]; then
93 if [ "0$MAXLOAD" -gt "0" ]; then
94 ASTARGS="$ASTARGS -L $MAXLOAD"
96 if [ "0$MAXCALLS" -gt "0" ]; then
97 ASTARGS="$ASTARGS -M $MAXCALLS"
99 if [ "0$VERBOSITY" -gt "0" ]; then
100 for i in `seq 1 $VERBOSITY`; do
101 ASTARGS="$ASTARGS -v"
103 # -v implies -f, so we override that implicit specification here
104 ASTARGS="$ASTARGS -F"
106 if [ "x$INTERNALTIMING" = "xyes" ]; then
107 ASTARGS="$ASTARGS -I"
109 if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
110 ASTARGS="$ASTARGS -t"
112 if test "x$COLOR" = "xno" ; then
113 ASTARGS="$ASTARGS -n"
115 # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already running (as LSB expects):
116 start-stop-daemon --start --oknodo --exec $DAEMON -- $ASTARGS
120 log_begin_msg "Stopping $DESC: $NAME"
121 # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already stopped (as LSB expects):
122 start-stop-daemon --stop --oknodo --exec $DAEMON
126 echo "Reloading $DESC configuration files."
127 $DAEMON -rx 'module reload' > /dev/null 2> /dev/null
129 restart|force-reload)
131 sleep 2 # It needs some time to really be stopped.
133 # "restart|force-reload" starts Asterisk and returns 0 even if Asterisk was stopped (as LSB expects).
136 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
140 echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2