e4976bb61f7278a0096e975332852f6c7be4b6ad
[asterisk/asterisk.git] / contrib / init.d / rc.suse.asterisk
1 #!/bin/sh
2 # $Id: asterisk,v 1.3 2005/11/17 22:30:01 Gregory Boehnlein <damin@nacs.net>
3 #
4 # asterisk    Starts, Stops and Reloads Asterisk.
5 #
6 # chkconfig: 2345 40 60
7 # description: Asterisk PBX and telephony daemon.
8 # processname: asterisk
9 # pidfile: /var/run/asterisk.pid
10 #
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
15 #
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' 
22
23 ### BEGIN INIT INFO
24 # Provides:                    asterisk
25 # Required-Start:      +dahdi $network $named
26 # Required-Stop:
27 # Default-Start:     3 5
28 # Default-Stop:      0 1 2 4 6
29 # Description: dahdi - dahdi modules for Asterisk
30 ### END INIT INFO
31
32 # Source function library.
33 . /lib/lsb/init-functions
34
35 if ! [ -x /usr/sbin/asterisk ] ; then
36         echo "ERROR: /usr/sbin/asterisk not found"
37         exit 0
38 fi
39
40 if ! [ -d /etc/asterisk ] ; then
41         echo "ERROR: /etc/asterisk directory not found"
42         exit 0
43 fi
44
45 # Uncomment this ONLY if you know what you are doing.
46 # export LD_ASSUME_KERNEL=2.4.1
47
48 # Full path to asterisk binary
49 DAEMON=/usr/sbin/asterisk
50
51 # Full path to safe_asterisk script
52 SAFE_ASTERISK=/usr/sbin/safe_asterisk
53
54 # Uncomment the following and set them to the user/groups that you
55 # want to run Asterisk as. NOTE: this requires substantial work to
56 # be sure that Asterisk's environment has permission to write the
57 # files required  for  its  operation, including logs, its comm
58 # socket, the asterisk database, etc.
59 #AST_USER="asterisk"
60 #AST_GROUP="asterisk"
61
62 # Allow configuration overrides in /etc/sysconfig/asterisk
63 CONFIG0=`readlink $0`
64 if [ "$CONFIG0" = "" ]; then
65         CONFIGFILE=/etc/sysconfig/`basename $0`
66 else
67         CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
68 fi
69 [ -r $CONFIGFILE ] && . $CONFIGFILE
70
71 RETVAL=0
72
73 start() {
74         # Start daemons.
75
76         # Check if Asterisk is already running.  If it is, then bug out, because
77         # starting Asterisk when Asterisk is already running is very bad.
78         VERSION=`/usr/sbin/asterisk -rx 'core show version'`
79         if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
80                 echo "Asterisk is already running.  $0 will exit now."
81                 exit 1
82         fi
83
84         echo -n $"Starting asterisk: "
85         if [ -f $SAFE_ASTERISK ] ; then
86                 DAEMON=$SAFE_ASTERISK
87         fi
88         if [ $AST_USER ] ; then
89                 ASTARGS="-U $AST_USER"
90         fi
91         if [ $AST_GROUP ] ; then
92                 ASTARGS="`echo $ASTARGS` -G $AST_GROUP"
93         fi
94         if [ $ALTCONF ]; then
95                 ASTARGS="$ASTARGS -C $ALTCONF"
96         fi
97         if [ "x$COREDUMP" = "xyes" ]; then
98                 ASTARGS="$ASTARGS -g"
99         fi
100         if [ "0$MAXLOAD" -gt "0" ]; then
101                 ASTARGS="$ASTARGS -L $MAXLOAD"
102         fi
103         if [ "0$MAXCALLS" -gt "0" ]; then
104                 ASTARGS="$ASTARGS -M $MAXCALLS"
105         fi
106         if [ "$VERBOSITY" -gt "0" ]; then
107                 for i in `seq 1 $VERBOSITY`; do
108                         ASTARGS="$ASTARGS -v"
109                 done
110         fi
111         if [ "x$INTERNALTIMING" = "xyes" ]; then
112                 ASTARGS="$ASTARGS -I"
113         fi
114         if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
115                 ASTARGS="$ASTARGS -t"
116         fi
117         if [ "x$COLOR" = "xyes" ]; then
118                 export TERM=linux
119                 sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 &
120         else
121                 $DAEMON $ASTARGS
122         fi
123         RETVAL=$?
124         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
125         echo
126         return $RETVAL
127 }
128
129 stop() {
130         # Stop daemons.
131         echo -n $"Shutting down asterisk: "
132         killproc asterisk
133         RETVAL=$?
134         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
135         echo
136         return $RETVAL
137 }
138
139 restart() {
140         stop
141         start
142 }
143
144 reload() {
145         $DAEMON -rx 'module reload' > /dev/null 2> /dev/null
146 }
147
148 # See how we were called.
149 case "$1" in
150   start)
151         start
152         ;;
153   stop)
154         stop
155         ;;
156   restart)
157         restart
158         ;;
159   reload)
160         reload
161         ;;
162   condrestart)
163         [ -f /var/lock/subsys/asterisk ] && restart || :
164         ;;
165   status)
166         status asterisk
167         ;;
168   *)
169         echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"
170         exit 1
171 esac
172
173 exit $?