2 # Written by Miquel van Smoorenburg <miquels@cistron.nl>.
3 # Modified for Debian GNU/Linux
4 # by Ian Murdock <imurdock@gnu.ai.mit.edu>.
5 # Clamav version by Magnus Ekdahl <magnus@debian.org>
6 # Nagios version by Sean Finney <seanius@debian.org> and probably others
7 # nagios2 version by Marc Haber <mh+debian-packages@zugschlus.de>
8 # nagios3 version by Alexander Wirt <formorer@debian.org>
12 # Required-Start: $local_fs $remote_fs $syslog $named $network $time
13 # Required-Stop: $local_fs $remote_fs $syslog $named $network
16 # Default-Start: 2 3 4 5
18 # Short-Description: nagios host/service/network monitoring and management system
19 # Description: nagios is a monitoring and management system for hosts, services and networks.
24 . /lib/lsb/init-functions
26 DAEMON=/usr/sbin/nagios3
28 DESC="nagios3 monitoring daemon"
29 NAGIOSCFG="/etc/nagios3/nagios.cfg"
30 CGICFG="/etc/nagios3/cgi.cfg"
33 [ -x "$DAEMON" ] || exit 0
34 [ -r /etc/default/nagios3 ] && . /etc/default/nagios3
37 # this is from madduck on IRC, 2006-07-06
38 # There should be a better possibility to give daemon error messages
39 # and/or to log things
43 [[:digit:]]*) success=$1; shift;;
46 log_action_begin_msg "$1"; shift
47 log_action_end_msg ${success:-0} "$*"
51 #nagios3-core can be installed without -cgi
54 check_cmd=$(get_config nagios_check_command $CGICFG)
55 if [ ! "$check_cmd" ]; then
56 log 6 "unable to determine nagios_check_command from $CGICFG!"
60 #use hardcoded default version
61 check_cmd="/usr/lib/nagios/plugins/check_nagios /var/cache/nagios3/status.dat 5 '/usr/sbin/nagios3'"
64 eval $check_cmd >/dev/null
66 if [ -f "$THEPIDFILE" ]; then
67 pid="$(cat $THEPIDFILE)"
68 if [ "$pid" ] && kill -0 $pid >/dev/null 2>/dev/null; then
72 return 1 # Isn't started
78 # grab a config option from nagios.cfg (or possibly another nagios config
79 # file if specified). everything after the '=' is echo'd out, making
80 # this a nice generalized way to get requested settings.
84 set -- `grep ^$1 $2 | sed 's@=@ @'`
86 set -- `grep ^$1 $NAGIOSCFG | sed 's@=@ @'`
93 if $DAEMON -v $NAGIOSCFG >/dev/null 2>&1 ; then
94 # First get the user/group etc Nagios is running as
95 nagios_user="$(get_config nagios_user)"
96 nagios_group="$(get_config nagios_group)"
97 log_file="$(get_config log_file)"
98 log_dir="$(dirname $log_file)"
100 return 0 # Config is ok
102 # config is not okay, so let's barf the error to the user
103 $DAEMON -v $NAGIOSCFG
107 check_named_pipe () {
108 nagiospipe="$(get_config command_file)"
109 if [ -p "$nagiospipe" ]; then
110 return 1 # a named pipe exists
111 elif [ -e "$nagiospipe" ];then
114 return 0 # no named pipe exists
118 if [ ! -f "$NAGIOSCFG" ]; then
119 log_failure_msg "There is no configuration file for Nagios 3."
123 THEPIDFILE=$(get_config "lock_file")
124 [ -n "$THEPIDFILE" ] || THEPIDFILE='/var/run/nagios3/nagios.pid'
127 DIRECTORY=$(dirname $THEPIDFILE)
128 [ ! -d $DIRECTORY ] && mkdir -p $DIRECTORY
129 chown nagios:nagios $DIRECTORY
131 if ! check_started; then
132 if ! check_named_pipe; then
133 log_action_msg "named pipe exists - removing"
136 if check_config; then
137 start_daemon -n $NICENESS -p $THEPIDFILE $DAEMON -d $NAGIOSCFG
140 log_failure_msg "errors in config!"
145 log_warning_msg "already running!"
151 killproc -p $THEPIDFILE
153 if [ `pidof nagios3 | wc -l ` -gt 0 ]; then
154 echo -n "Waiting for $NAME daemon to die.."
156 while [ `pidof nagios3 | wc -l ` -gt 0 ]; do
157 cnt=`expr "$cnt" + 1`
158 if [ "$cnt" -gt 15 ]; then
159 kill -9 `pidof nagios3`
167 if ! check_named_pipe; then
170 if [ -n "$ret" ]; then
179 log_action_begin_msg "checking $DAEMON"
180 if check_started; then
181 log_action_end_msg 0 "running"
183 if [ -e "$THEPIDFILE" ]; then
184 log_action_end_msg 1 "$DAEMON failed"
187 log_action_end_msg 1 "not running"
196 if check_config; then
197 if check_started; then
198 killproc -p $THEPIDFILE $DAEMON 1
200 log_warning_msg "Not running."
203 log_failure_msg "errors in config!"
210 $DAEMON -v $NAGIOSCFG
215 log_daemon_msg "Starting $DESC" "$NAME"
220 log_daemon_msg "Stopping $DESC" "$NAME"
225 log_daemon_msg "Restarting $DESC" "$NAME"
227 if [ -z "$?" -o "$?" = "0" ]; then
233 log_daemon_msg "Reloading $DESC configuration files" "$NAME"
244 log_failure_msg "Usage: $0 {start|stop|restart|reload|force-reload|status}" >&2