Merge damin's updated redhat scripts for starting/stopping/reloading asterisk
[asterisk/asterisk.git] / contrib / init.d / rc.redhat.asterisk
1 #!/bin/sh
2 # $Id: asterisk,v 1.2 2004/07/18 20:24:07 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 # Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
12 # - Updated Version to 1.2
13 # - Added test for safe_asterisk
14 # - Verified SIGTERM issued by "killproc" ensures "stop gracefully"
15 # - Added support for -U and -G command line options
16 # - Modified "reload" to call asterisk -rx 'reload' 
17
18 # Source function library.
19 . /etc/rc.d/init.d/functions
20
21 [ -x /usr/sbin/asterisk ] || exit 0
22 [ -d /etc/asterisk ] || exit 0
23
24 # Leave this set unless you know what you are doing.
25 export LD_ASSUME_KERNEL=2.4.1
26
27 # Full path to asterisk binary
28 DAEMON=/usr/sbin/asterisk
29
30 # Full path to safe_asterisk script
31 SAFE_ASTERISK=/usr/sbin/safe_asterisk
32
33 # Uncomment the following and set them to the user/groups that you
34 # want to run Asterisk as. NOTE: this requires substantial work to
35 # be sure that Asterisk's environment has permission to write the
36 # files required  for  its  operation, including logs, its comm
37 # socket, the asterisk database, etc.
38 #AST_USER="asterisk"
39 #AST_GROUP="asterisk"
40
41 RETVAL=0
42
43 start() {
44         # Start daemons.
45         echo -n $"Starting asterisk: "
46         if [ -f $SAFE_ASTERISK ] ; then
47                 DAEMON=$SAFE_ASTERISK
48         fi
49         if [ $AST_USER ] ; then
50                 ASTARGS="-U $AST_USER"
51         fi
52         if [ $AST_GROUP ] ; then
53                 ASTARGS="`echo $ASTARGS` -G $AST_GROUP"
54         fi
55         daemon $DAEMON $ASTARGS
56         RETVAL=$?
57         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
58         echo
59         return $RETVAL
60 }
61
62 stop() {
63         # Stop daemons.
64         echo -n $"Shutting down asterisk: "
65         killproc asterisk
66         RETVAL=$?
67         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
68         echo
69         return $RETVAL
70 }
71
72 restart() {
73         stop
74         start
75 }
76
77 reload() {
78         $DAEMON -rx 'reload' > /dev/null 2> /dev/null
79 }
80
81 # See how we were called.
82 case "$1" in
83   start)
84         start
85         ;;
86   stop)
87         stop
88         ;;
89   restart)
90         restart
91         ;;
92   reload)
93         reload
94         ;;
95   condrestart)
96         [ -f /var/lock/subsys/asterisk ] && restart || :
97         ;;
98   status)
99         status asterisk
100         ;;
101   *)
102         echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"
103         exit 1
104 esac
105
106 exit $?