e94df915a45bf885f20f4a35bd89d927ed08a217
[packages/precise/mcollective.git] / ext / solaris / mcollective.init
1 #!/bin/sh
2 #
3 # mcollective   Application Server for STOMP based agents
4 #
5 # description: mcollective lets you build powerful Stomp compatible middleware clients in ruby without having to worry too
6 #              much about all the setup and management of a Stomp connection, it also provides stats, logging and so forth
7 #              as a bonus.
8 #
9
10 RUBYLIB=/opt/csw/lib/ruby/site_ruby/1.8:$RUBYLIB
11 export RUBYLIB
12
13 mcollectived="/opt/csw/sbin/mcollectived"
14
15 lock="/var/lock/mcollective"
16
17 # PID directory
18 pidfile="/var/run/mcollectived.pid"
19
20 # Check that binary exists
21 if [ ! -f  $mcollectived ] 
22 then
23   echo "mcollectived binary not found"
24   exit 1
25 fi
26
27 # See how we were called.
28 case "$1" in
29   start)
30         if [ -f ${lock} ]; then
31             # we were not shut down correctly
32             if [ -s ${pidfile} ]; then
33                 kill `cat ${pidfile}` >/dev/null 2>&1
34             fi
35             rm -f ${pidfile}
36
37             rm -f ${lock}
38             sleep 2
39         fi
40
41         rm -f ${pidfile}
42
43         ${mcollectived} --pid=${pidfile} --config="/etc/mcollective/server.cfg"
44         if [ $? = 0 ]; then
45             touch $lock
46             exit 0
47         else
48             exit 1
49         fi
50         ;;
51   stop)
52         if [ -s ${pidfile} ]; then
53           kill `cat ${pidfile}` >/dev/null 2>&1
54         fi
55         rm -f ${pidfile}
56
57         rm -f $lock
58         ;;
59   restart)
60         $0 stop
61         sleep 2
62         $0 start
63         ;;
64   condrestart)
65         if [ -f $lock ]; then
66             $0 stop
67             # avoid race
68             sleep 2
69             $0 start
70         fi
71         ;;
72   status)
73         if [ -f ${lock} ]; then
74             if [ -s ${pidfile} ]; then
75                if [ -e /proc/`cat ${pidfile}` ]; then
76                   echo "mcollectived (`cat ${pidfile}`) is running"
77                   exit 0
78                else
79                   echo "mcollectived (`cat ${pidfile}`) is NOT running"
80                   exit 1
81                fi
82             fi
83         else
84             echo "mcollectived: service not started"
85             exit 1
86         fi
87   ;;
88         force-reload)
89                 echo "not implemented"
90         ;;
91   *)
92         echo "Usage: $0 {start|stop|restart|condrestart|status}"
93         exit 1
94         ;;
95 esac
96 exit 0