Merged revisions 7285,7299,7310,7329 via svnmerge from
[asterisk/asterisk.git] / contrib / init.d / rc.redhat.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 # Source function library.
24 . /etc/rc.d/init.d/functions
25
26 if ! [ -x /usr/sbin/asterisk ] ; then
27         echo "ERROR: /usr/sbin/asterisk not found"
28         exit 0
29 fi
30
31 if ! [ -d /etc/asterisk ] ; then
32         echo "ERROR: /etc/asterisk directory not found"
33         exit 0
34 fi
35
36 # Uncomment this ONLY if you know what you are doing.
37 # export LD_ASSUME_KERNEL=2.4.1
38
39 # Full path to asterisk binary
40 DAEMON=/usr/sbin/asterisk
41
42 # Full path to safe_asterisk script
43 SAFE_ASTERISK=/usr/sbin/safe_asterisk
44
45 # Uncomment the following and set them to the user/groups that you
46 # want to run Asterisk as. NOTE: this requires substantial work to
47 # be sure that Asterisk's environment has permission to write the
48 # files required  for  its  operation, including logs, its comm
49 # socket, the asterisk database, etc.
50 #AST_USER="asterisk"
51 #AST_GROUP="asterisk"
52
53 RETVAL=0
54
55 start() {
56         # Start daemons.
57         echo -n $"Starting asterisk: "
58         if [ -f $SAFE_ASTERISK ] ; then
59                 DAEMON=$SAFE_ASTERISK
60         fi
61         if [ $AST_USER ] ; then
62                 ASTARGS="-U $AST_USER"
63         fi
64         if [ $AST_GROUP ] ; then
65                 ASTARGS="`echo $ASTARGS` -G $AST_GROUP"
66         fi
67         daemon $DAEMON $ASTARGS
68         RETVAL=$?
69         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
70         echo
71         return $RETVAL
72 }
73
74 stop() {
75         # Stop daemons.
76         echo -n $"Shutting down asterisk: "
77         killproc asterisk
78         RETVAL=$?
79         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
80         echo
81         return $RETVAL
82 }
83
84 restart() {
85         stop
86         start
87 }
88
89 reload() {
90         $DAEMON -rx 'reload' > /dev/null 2> /dev/null
91 }
92
93 # See how we were called.
94 case "$1" in
95   start)
96         start
97         ;;
98   stop)
99         stop
100         ;;
101   restart)
102         restart
103         ;;
104   reload)
105         reload
106         ;;
107   condrestart)
108         [ -f /var/lock/subsys/asterisk ] && restart || :
109         ;;
110   status)
111         status asterisk
112         ;;
113   *)
114         echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"
115         exit 1
116 esac
117
118 exit $?