]> git.pld-linux.org Git - packages/nagios.git/blame_incremental - nagios.init
- update configs
[packages/nagios.git] / nagios.init
... / ...
CommitLineData
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.
19if 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
24else
25 exit 0
26fi
27
28cfg_file=/etc/nagios/nagios.cfg
29
30# check for precache
31precached_object_file=$(awk -F= '/^precached_object_file/{print $2}' $cfg_file)
32
33# configtest itself
34configtest() {
35 /usr/sbin/nagios ${precached_object_file:+-p} -v $cfg_file
36}
37
38# wrapper for configtest:
39checkconfig() {
40 local details=${1:-0}
41
42 if [ $details = 1 ]; then
43 # run config test and display report (status action)
44 show "Checking %s configuration" "Nagios"; busy
45 local out
46 out=`configtest 2>&1`
47 RETVAL=$?
48 if [ $RETVAL = 0 ]; then
49 ok
50 else
51 fail
52 fi
53 [ "$out" ] && echo >&2 "$out"
54 else
55 # run config test and abort with nice message if failed
56 # (for actions checking status before action).
57 configtest >/dev/null 2>&1
58 RETVAL=$?
59 if [ $RETVAL != 0 ]; then
60 show "Checking %s configuration" "Nagios"; fail
61 nls 'Configuration test failed. See details with %s "checkconfig"' $0
62 exit $RETVAL
63 fi
64 fi
65}
66
67start() {
68 # Check if the service is already running?
69 if [ -f /var/lock/subsys/nagios ]; then
70 msg_already_running "Nagios"
71 return
72 fi
73
74 checkconfig
75 msg_starting "Nagios"
76
77 # remove stale cmd pipe (or nagios won't start if it exists)
78 rm -f /var/lib/nagios/rw/nagios.cmd
79
80 # we're safe to use -x as we did verify config prior startup
81 # precached object file also is created in configtest.
82 daemon /usr/sbin/nagios ${precached_object_file:+-u} -x -d $cfg_file
83 RETVAL=$?
84 if [ $RETVAL -eq 0 ]; then
85 touch /var/lock/subsys/nagios
86 fi
87}
88
89stop() {
90 # Stop daemons.
91 if [ ! -f /var/lock/subsys/nagios ]; then
92 msg_not_running "Nagios"
93 return
94 fi
95
96 msg_stopping "Nagios"
97 killproc nagios -TERM
98 rm -f /var/lock/subsys/nagios > /dev/null 2>&1
99}
100
101reload() {
102 if [ ! -f /var/lock/subsys/nagios ]; then
103 msg_not_running "Nagios"
104 RETVAL=7
105 return
106 fi
107
108 checkconfig
109 msg_reloading "Nagios"
110
111 # NOTE: precached object file is created in configtest.
112 killproc nagios -HUP
113 RETVAL=$?
114}
115
116condrestart() {
117 if [ ! -f /var/lock/subsys/nagios ]; then
118 msg_not_running "Nagios"
119 RETVAL=$1
120 return
121 fi
122
123 checkconfig
124 stop
125 start
126}
127
128RETVAL=0
129# See how we were called.
130case "$1" in
131 start)
132 start
133 ;;
134 stop)
135 stop
136 ;;
137 restart)
138 checkconfig
139 stop
140 start
141 ;;
142 try-restart)
143 condrestart 0
144 ;;
145 reload|force-reload)
146 reload
147 ;;
148 checkconfig|configtest)
149 checkconfig 1
150 ;;
151 status)
152 status nagios
153 RETVAL=$?
154 ;;
155*)
156 msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
157 exit 3
158esac
159
160exit $RETVAL
This page took 0.034669 seconds and 4 git commands to generate.