f599f4a8b5a6010ed0559bcf0de085ac7b82b59e
[packages/precise/mcollective.git] / ext / debian / 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/mcollectived.pid"
28
29 name="mcollective"
30 mcollectived=/usr/sbin/mcollectived
31 daemonopts="--pid=${pidfile}  --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 # create pid file if it does not exist
45 [ ! -f ${pidfile} ] && { touch ${pidfile} ; }
46
47 # See how we were called.
48 case "$1" in
49     start)
50         echo "Starting daemon: " $name
51         # start the program
52         start-stop-daemon -S -p ${pidfile} --oknodo -q -a ${mcollectived} -- ${daemonopts}
53         [ $? = 0 ] && { exit 0 ; } || { exit 1 ; }
54         log_success_msg "mcollective started"
55         touch $lock
56         ;;
57     stop)
58         echo "Stopping daemon: " $name
59         start-stop-daemon -K -R 5 -s "TERM" --oknodo -q -p ${pidfile}
60         [ $? = 0 ] && { exit 0 ; } || { exit 1 ; }
61         log_success_msg "mcollective stopped"
62         ;;
63     restart)
64         echo "Restarting daemon: " $name
65         $0 stop
66         sleep 2
67         $0 start
68         [ $? = 0 ] && { echo "mcollective restarted" ; exit 0 ; }
69         ;;
70     condrestart)
71         if [ -f $lock ]; then
72             $0 stop
73             # avoid race
74             sleep 2
75             $0 start
76         fi
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