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__
29 # Uncomment this ONLY if you know what you are doing.
30 # export LD_ASSUME_KERNEL=2.4.1
32 # Uncomment the following and set them to the user/groups that you
33 # want to run Asterisk as. NOTE: this requires substantial work to
34 # be sure that Asterisk's environment has permission to write the
35 # files required for its operation, including logs, its comm
36 # socket, the asterisk database, etc.
42 if ! [ -x $DAEMON ] ; then
43 echo "ERROR: $DAEMON not found"
47 if ! [ -d $ASTETCDIR ] ; then
48 echo "ERROR: $ASTETCDIR directory not found"
52 # Use the LSB standar functions for services management
53 . /lib/lsb/init-functions
57 # Check if Asterisk is already running. If it is, then bug out, because
58 # starting up Asterisk when Asterisk is already running is very bad.
59 VERSION=`${DAEMON} -rx 'core show version' || ${TRUE}`
60 if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
61 echo "Asterisk is already running. $0 will exit now."
65 log_begin_msg "Starting $DESC: $NAME"
66 if [ ! -d $ASTVARRUNDIR ]; then
67 mkdir -p $ASTVARRUNDIR
70 if [ $AST_USER ] ; then
71 ASTARGS="-U $AST_USER"
72 chown $AST_USER $ASTVARRUNDIR
74 if [ $AST_GROUP ] ; then
75 ASTARGS="$ASTARGS -G $AST_GROUP"
76 chgrp $AST_GROUP $ASTVARRUNDIR
78 # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already running (as LSB expects):
79 start-stop-daemon --start --oknodo --exec $DAEMON -- $ASTARGS
83 log_begin_msg "Stopping $DESC: $NAME"
84 # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already stopped (as LSB expects):
85 start-stop-daemon --stop --oknodo --exec $DAEMON
89 echo "Reloading $DESC configuration files."
90 $DAEMON -rx 'module reload' > /dev/null 2> /dev/null
94 sleep 2 # It needs some time to really be stopped.
96 # "restart|force-reload" starts Asterisk and returns 0 even if Asterisk was stopped (as LSB expects).
100 echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2