90c9b59d2d68de0d9c8e6467ecc251271ce5a33e
[packages/precise/mcollective.git] / ext / redhat / mcollective.init
1 #!/bin/sh
2 #
3 # mcollective   Application Server for STOMP based agents
4 #
5 # chkconfig:    - 24 76
6 #
7 # description:  mcollective lets you build powerful Stomp compatible middleware clients in ruby without having to worry too
8 #               much about all the setup and management of a Stomp connection, it also provides stats, logging and so forth
9 #               as a bonus.
10 #
11 ### BEGIN INIT INFO
12 # Provides:          mcollective
13 # Required-Start:    $remote_fs
14 # Required-Stop:     $remote_fs
15 # Short-Description: Start daemon at boot time
16 # Description:       Enable service provided by daemon.
17 ### END INIT INFO
18
19 mcollectived="/usr/sbin/mcollectived"
20 pidfile="/var/run/mcollectived.pid"
21 if [ -d /var/lock/subsys ]; then
22     # RedHat/CentOS/etc who use subsys
23     lockfile="/var/lock/subsys/mcollective"
24 else
25     # The rest of them
26     lockfile="/var/lock/mcollective"
27 fi
28
29 # Check that binary exists
30 if ! [ -f $mcollectived ]; then
31     echo "mcollectived binary not found"
32     exit 5
33 fi
34
35 # Source function library.
36 . /etc/init.d/functions
37
38 if [ -f /etc/sysconfig/mcollective ]; then
39     . /etc/sysconfig/mcollective
40 fi
41
42 # Determine if we can use the -p option to daemon, killproc, and status.
43 # RHEL < 5 can't.
44 if status | grep -q -- '-p' 2>/dev/null; then
45     daemonopts="--pidfile $pidfile"
46     pidopts="-p $pidfile"
47 fi
48
49 start() {
50     echo -n "Starting mcollective: "
51     # Only try to start if not already started
52     if ! rh_status_q; then
53       daemon ${daemonopts} ${mcollectived} --pid=${pidfile} --config="/etc/mcollective/server.cfg"
54     fi
55     # This will be 0 if mcollective is already running
56     RETVAL=$?
57     echo
58     [ $RETVAL -eq 0 ] && touch ${lockfile}
59     return $RETVAL
60 }
61
62 stop() {
63     echo -n "Shutting down mcollective: "
64     # If running, try to stop it
65     if rh_status_q; then
66       killproc ${pidopts} -d 10 ${mcollectived}
67     else
68       # Non-zero status either means lockfile and pidfile need cleanup (1 and 2)
69       # or the process is already stopped (3), so we can just call true to
70       # trigger the cleanup that happens below.
71       true
72     fi
73     RETVAL=$?
74     echo
75     [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
76     return $RETVAL
77 }
78
79 restart() {
80     stop
81     start
82 }
83
84 reload_agents() {
85     echo -n "Reloading mcollective agents: "
86     killproc ${pidopts} ${mcollectived} -USR1
87     RETVAL=$?
88     echo
89     return $RETVAL
90 }
91
92 reload_loglevel() {
93     echo -n "Cycling mcollective logging level: "
94     killproc ${pidopts} ${mcollectived} -USR2
95     RETVAL=$?
96     echo
97     return $RETVAL
98 }
99
100 rh_status() {
101     status ${pidopts} ${mcollectived}
102     RETVAL=$?
103     return $RETVAL
104 }
105
106 rh_status_q() {
107     rh_status >/dev/null 2>&1
108 }
109
110 # See how we were called.
111 case "$1" in
112     start)
113         start
114         ;;
115     stop)
116         stop
117         ;;
118     restart)
119         restart
120         ;;
121     condrestart)
122         rh_status_q || exit 0
123         restart
124         ;;
125     reload-agents)
126         reload_agents
127         ;;
128     reload-loglevel)
129         reload_loglevel
130         ;;
131     status)
132         rh_status
133         ;;
134     *)
135         echo "Usage: mcollectived {start|stop|restart|condrestart|reload-agents|reload-loglevel|status}"
136         RETVAL=2
137         ;;
138 esac
139 exit $RETVAL