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