Fix the init script so mcollective can be restarted properly
[packages/trusty/mcollective.git] / mcollective.init
1 #!/bin/sh
2 #
3 # mcollective   Application Server for STOMP based agents
4 #
5 #
6 # description:  mcollective lets you build powerful Stomp compatible middleware clients in ruby without having to worry too
7 #               much about all the setup and management of a Stomp connection, it also provides stats, logging and so forth
8 #               as a bonus.
9 #
10 ### BEGIN INIT INFO
11 # Provides:          mcollective
12 # Required-Start:    $remote_fs
13 # Required-Stop:     $remote_fs
14 # Default-Start:     2 3 4 5
15 # Default-Stop:      0 1 6
16 # Short-Description: Start daemon at boot time
17 # Description:       Enable service provided by mcollective.
18 ### END INIT INFO
19
20 # check permissions
21
22 uid=`id -u`
23 [ $uid -gt 0 ] && { echo "You need to be root to run file" ; exit 4 ; }
24
25
26 # PID directory
27 pidfile="/var/run/mcollective.pid"
28
29 name="mcollective"
30 mcollectived=/usr/sbin/mcollectived
31 daemonopts="--config=/etc/mcollective/server.cfg"
32
33
34 # Source function library.
35 . /lib/lsb/init-functions
36
37 # Check that binary exists
38 if ! [ -f $mcollectived ]
39 then
40     echo "mcollectived binary not found"
41     exit 5
42 fi
43
44 # See how we were called.
45 case "$1" in
46     start)
47         echo "Starting daemon: " $name
48         # start the program
49         if [ -f "$pidfile" ]; then
50                 if [ -L "/proc/$(cat $pidfile)/exe" ] ; then
51                         echo MCollective appears to be running
52                         exit 1
53                 else
54                         /sbin/start-stop-daemon --start -b --quiet --oknodo -m --pidfile $pidfile --exec $mcollectived -- $daemonopts
55                 [ $? = 0 ] && { exit 0 ; } || { exit 1 ; }
56                 fi
57         else
58                 /sbin/start-stop-daemon --start -b --quiet --oknodo -m --pidfile $pidfile --exec $mcollectived -- $daemonopts
59         fi
60         log_success_msg "mcollective started"
61         ;;
62     stop)
63         echo "Stopping daemon: " $name
64         /sbin/start-stop-daemon --stop -q --pidfile $pidfile
65         if [ -f $pidfile ]; then
66                 rm -f $pidfile
67         fi
68         [ $? = 0 ] && { exit 0 ; } || { exit 1 ; }
69         log_success_msg "mcollective stopped"
70         ;;
71     restart)
72         echo "Restarting daemon: " $name
73         $0 stop
74         sleep 2
75         $0 start
76         [ $? = 0 ] && { echo "mcollective restarted" ; exit 0 ; }
77         ;;
78     status)
79         status_of_proc -p ${pidfile} ${mcollectived} ${name} && exit 0 || exit $?
80         ;;
81     *)
82         echo "Usage: mcollectived {start|stop|restart|condrestart|status}"
83         exit 2
84         ;;
85 esac