2 # $Id: asterisk,v 1.3 2005/11/17 22:30:01 Gregory Boehnlein <damin@nacs.net>
4 # asterisk Starts, Stops and Reloads Asterisk.
6 # chkconfig: 2345 40 60
7 # description: Asterisk PBX and telephony daemon.
8 # processname: asterisk
9 # pidfile: /var/run/asterisk.pid
11 # Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net>
12 # - Updated Version to 1.3
13 # - Reversed behavior of LD_ASSUME_KERNEL=2.4.1
14 # - Added detailed failure messages
16 # Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
17 # - Updated Version to 1.2
18 # - Added test for safe_asterisk
19 # - Verified SIGTERM issued by "killproc" ensures "stop gracefully"
20 # - Added support for -U and -G command line options
21 # - Modified "reload" to call asterisk -rx 'reload'
25 # Required-Start: $network $syslog $named $local_fs $remote_fs
26 # Required-Stop: $network $syslog $named $local_fs $remote_fs
27 # Should-Start: dahdi misdn lcr wanrouter mysql postgresql
28 # Should-Stop: dahdi misdn lcr wanrouter mysql postgresql
29 # Default-Start: 2 3 4 5
31 # Short-Description: Asterisk PBX
32 # Description: the Asterisk Open Source PBX
35 # Source function library.
36 . /lib/lsb/init-functions
38 if ! [ -x /usr/sbin/asterisk ] ; then
39 echo "ERROR: /usr/sbin/asterisk not found"
43 if ! [ -d /etc/asterisk ] ; then
44 echo "ERROR: /etc/asterisk directory not found"
48 # Uncomment this ONLY if you know what you are doing.
49 # export LD_ASSUME_KERNEL=2.4.1
51 # Full path to asterisk binary
52 DAEMON=/usr/sbin/asterisk
54 # Full path to safe_asterisk script
55 SAFE_ASTERISK=/usr/sbin/safe_asterisk
57 # Uncomment the following and set them to the user/groups that you
58 # want to run Asterisk as. NOTE: this requires substantial work to
59 # be sure that Asterisk's environment has permission to write the
60 # files required for its operation, including logs, its comm
61 # socket, the asterisk database, etc.
65 # Allow configuration overrides in /etc/sysconfig/asterisk
67 if [ "$CONFIG0" = "" ]; then
68 CONFIGFILE=/etc/sysconfig/`basename $0`
70 CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
72 [ -r $CONFIGFILE ] && . $CONFIGFILE
79 # Check if Asterisk is already running. If it is, then bug out, because
80 # starting Asterisk when Asterisk is already running is very bad.
81 VERSION=`/usr/sbin/asterisk -rx 'core show version'`
82 if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
83 echo "Asterisk is already running. $0 will exit now."
87 echo -n $"Starting asterisk: "
88 if [ -f $SAFE_ASTERISK ] ; then
91 if [ $AST_USER ] ; then
92 ASTARGS="-U $AST_USER"
94 if [ $AST_GROUP ] ; then
95 ASTARGS="`echo $ASTARGS` -G $AST_GROUP"
98 ASTARGS="$ASTARGS -C $ALTCONF"
100 if [ "x$COREDUMP" = "xyes" ]; then
101 ASTARGS="$ASTARGS -g"
103 if [ "0$MAXLOAD" -gt "0" ]; then
104 ASTARGS="$ASTARGS -L $MAXLOAD"
106 if [ "0$MAXCALLS" -gt "0" ]; then
107 ASTARGS="$ASTARGS -M $MAXCALLS"
109 if [ "0$VERBOSITY" -gt "0" ]; then
110 for i in `seq 1 $VERBOSITY`; do
111 ASTARGS="$ASTARGS -v"
114 if [ "x$INTERNALTIMING" = "xyes" ]; then
115 ASTARGS="$ASTARGS -I"
117 if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
118 ASTARGS="$ASTARGS -t"
120 if [ "x$COLOR" = "xyes" ]; then
122 sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 &
127 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
134 echo -n $"Shutting down asterisk: "
137 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
148 $DAEMON -rx 'module reload' > /dev/null 2> /dev/null
151 # See how we were called.
166 [ -f /var/lock/subsys/asterisk ] && restart || :
172 echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"