]> git.pld-linux.org Git - packages/nagios.git/blob - nagios.init
fix $HOME env var
[packages/nagios.git] / nagios.init
1 #!/bin/sh
2 #
3 # Nagios        Host/service/network monitoring daemon
4 #
5 # chkconfig:    345 85 24
6 # description:  Host/service/network monitoring daemon which uses snort as NIDS
7 #
8
9 # Source function library
10 . /etc/rc.d/init.d/functions
11
12 # Get network config
13 . /etc/sysconfig/network
14
15 # Get service config
16 [ -f /etc/sysconfig/nagios ] && . /etc/sysconfig/nagios
17
18 # Check that networking is up.
19 if is_yes "${NETWORKING}"; then
20         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
21                 msg_network_down "Nagios"
22                 exit 1
23         fi
24 else
25         exit 0
26 fi
27
28 cfg_file=/etc/nagios/nagios.cfg
29
30 # value to use for $HOME
31 # as pld initscript resets HOME=/tmp, plugins may inherit bad value
32 nagios_home=/usr/lib/nagios
33
34 # check for precache
35 precached_object_file=$(awk -F= '/^precached_object_file/{print $2}' $cfg_file)
36
37 # nagios pid file
38 pid_file=$(awk -F= '/^lock_file/{print $2}' $cfg_file)
39 pid_file=${pid_file:-/var/lib/nagios/nagios.pid}
40
41 # configtest itself
42 configtest() {
43         /usr/sbin/nagios ${precached_object_file:+-p} -v $cfg_file
44 }
45
46 # wrapper for configtest:
47 checkconfig() {
48         local details=${1:-0}
49
50         if [ $details = 1 ]; then
51                 # run config test and display report (status action)
52                 show "Checking %s configuration" "Nagios"; busy
53                 local out
54                 out=`configtest 2>&1`
55                 RETVAL=$?
56                 if [ $RETVAL = 0 ]; then
57                         ok
58                 else
59                         fail
60                 fi
61                 [ "$out" ] && echo >&2 "$out"
62         else
63                 # run config test and abort with nice message if failed
64                 # (for actions checking status before action).
65                 configtest >/dev/null 2>&1
66                 RETVAL=$?
67                 if [ $RETVAL != 0 ]; then
68                         show "Checking %s configuration" "Nagios"; fail
69                         nls 'Configuration test failed. See details with %s "checkconfig"' $0
70                         exit $RETVAL
71                 fi
72         fi
73 }
74
75 start() {
76         # Check if the service is already running?
77         if [ -f /var/lock/subsys/nagios ]; then
78                 msg_already_running "Nagios"
79                 return
80         fi
81
82         checkconfig
83         msg_starting "Nagios"
84
85         # remove stale cmd pipe (or nagios won't start if it exists)
86         rm -f /var/lib/nagios/rw/nagios.cmd
87
88         # we're safe to use -x as we did verify config prior startup
89         # precached object file also is created in configtest.
90         daemon env -i PATH="$PATH" HOME="$nagios_home" /usr/sbin/nagios ${precached_object_file:+-u} -x -d $cfg_file
91         RETVAL=$?
92         if [ $RETVAL -eq 0 ]; then
93                 touch /var/lock/subsys/nagios
94         fi
95 }
96
97 stop() {
98         # Stop daemons.
99         if [ ! -f /var/lock/subsys/nagios ]; then
100                 msg_not_running "Nagios"
101                 return
102         fi
103
104         msg_stopping "Nagios"
105         killproc --pidfile $pid_file nagios
106         rm -f /var/lock/subsys/nagios > /dev/null 2>&1
107 }
108
109 reload() {
110         if [ ! -f /var/lock/subsys/nagios ]; then
111                 msg_not_running "Nagios"
112                 RETVAL=7
113                 return
114         fi
115
116         checkconfig
117         msg_reloading "Nagios"
118
119         # NOTE: precached object file is created in configtest.
120         killproc --pidfile $pid_file nagios -HUP
121         RETVAL=$?
122 }
123
124 condrestart() {
125         if [ ! -f /var/lock/subsys/nagios ]; then
126                 msg_not_running "Nagios"
127                 RETVAL=$1
128                 return
129         fi
130
131         checkconfig
132         stop
133         start
134 }
135
136 RETVAL=0
137 # See how we were called.
138 case "$1" in
139   start)
140         start
141         ;;
142   stop)
143         stop
144         ;;
145   restart)
146         checkconfig
147         stop
148         start
149         ;;
150   try-restart)
151         condrestart 0
152         ;;
153   reload|force-reload)
154         reload
155         ;;
156   checkconfig|configtest)
157         checkconfig 1
158         ;;
159   status)
160         status --pidfile $pid_file nagios
161         RETVAL=$?
162         ;;
163 *)
164         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
165         exit 3
166 esac
167
168 exit $RETVAL
This page took 0.089136 seconds and 3 git commands to generate.