]> git.pld-linux.org Git - packages/monit.git/blob - monit.init
904511280492eae2a1688b642df58c054e51f26b
[packages/monit.git] / monit.init
1 #!/bin/sh
2 #
3 # monit         Monitoring daemon
4 #
5 # chkconfig:    345 99 01
6 # description:  Monitoring daemon
7 #
8
9 # Source function library
10 . /etc/rc.d/init.d/functions
11
12 # Get service config
13 [ -f /etc/sysconfig/monit ] && . /etc/sysconfig/monit
14
15 checkconfig() {
16         local out
17         out=$(monit -c /etc/monitrc -t 2>&1)
18         ret=$?
19         if [ $ret != 0 ]; then
20                 echo >&2 "$out"
21                 exit 1
22         fi
23 }
24
25 start() {
26         # Check if the service is already running?
27         if [ ! -f /var/lock/subsys/monit ]; then
28                 checkconfig
29                 msg_starting monit
30                 daemon /usr/sbin/monit -c /etc/monitrc -l syslog -d 60 -s /var/run/monit.state
31                 RETVAL=$?
32                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/monit
33         else
34                 msg_already_running monit
35         fi
36 }
37
38 stop() {
39         # Stop daemons.
40         if [ -f /var/lock/subsys/monit ]; then
41                 msg_stopping monit
42                 daemon --waitforname monit --waitfortime 10 monit -c /etc/monitrc quit
43                 rm -f /var/lock/subsys/monit > /dev/null 2>&1
44         else
45                 msg_not_running monit
46         fi
47 }
48
49 RETVAL=0
50 # See how we were called.
51 case "$1" in
52   start)
53         start
54         ;;
55   stop)
56         stop
57         ;;
58   restart)
59         checkconfig
60         stop
61         start
62         ;;
63   reload|force-reload)
64         if [ -f /var/lock/subsys/monit ]; then
65                 checkconfig
66                 msg_reloading monit
67                 daemon /usr/sbin/monit -c /etc/monitrc reload
68                 RETVAL=$?
69         else
70                 msg_not_running monit
71                 exit 7
72         fi
73         ;;
74   checkconfig)
75         checkconfig
76         echo "Config check OK"
77         ;;
78   status)
79         status monit
80         monit -c /etc/monitrc status
81         exit $?
82         ;;
83   *)
84         msg_usage "$0 {start|stop|restart|reload|force-reload|checkconfig|status}"
85         exit 3
86 esac
87
88 exit $RETVAL
This page took 0.021808 seconds and 2 git commands to generate.