Skip to content

Commit

Permalink
Basically reverting a bad patch from 30ab1ba. Rebuilt the daemon-init…
Browse files Browse the repository at this point in the history
… scripts back to something that should work on all systems. The patch must have only been tested on RHEL based systems and clearly would not work on Debian/SUSE/etc. - Scott Wilkerson
  • Loading branch information
Scott Wilkerson committed Mar 3, 2014
1 parent 2ba779b commit 95ee71a
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 91 deletions.
7 changes: 7 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Nagios Core 4 Change Log
########################

4.x.x - xx/xx/2014
------------------

FIXES
* Fixed bug #491,#553: Rebuilt the daemon-init scripts back to something that should work on all systems (Scott Wilkerson)


4.0.3 - 02/28/2014
------------------
ENHANCEMENTS
Expand Down
322 changes: 231 additions & 91 deletions daemon-init.in
Original file line number Diff line number Diff line change
@@ -1,54 +1,87 @@
#!/bin/sh

# Nagios Startup script for the Nagios monitoring daemon
#
# chkconfig: - 85 15
# description: Nagios is a service monitoring system
#
# chkconfig: 345 99 01
# description: Nagios network monitor
# processname: nagios
# config: /etc/nagios/nagios.cfg
# pidfile: /var/nagios/nagios.pid
# File : nagios
#
# Author : Jorge Sanchez Aymar ([email protected])
#
# Changelog :
#
# 1999-07-09 Karl DeBisschop <[email protected]>
# - setup for autoconf
# - add reload function
# 1999-08-06 Ethan Galstad <[email protected]>
# - Added configuration info for use with RedHat's chkconfig tool
# per Fran Boon's suggestion
# 1999-08-13 Jim Popovitch <[email protected]>
# - added variable for nagios/var directory
# - cd into nagios/var directory before creating tmp files on startup
# 1999-08-16 Ethan Galstad <[email protected]>
# - Added test for rc.d directory as suggested by Karl DeBisschop
# 2000-07-23 Karl DeBisschop <[email protected]>
# - Clean out redhat macros and other dependencies
# 2003-01-11 Ethan Galstad <[email protected]>
# - Updated su syntax (Gary Miller)
#
# Description: Starts and stops the Nagios monitor
# used to provide network services status.
#
### BEGIN INIT INFO
# Provides: nagios
# Required-Start: $local_fs $syslog $network
# Required-Stop: $local_fs $syslog $network
# Short-Description: start and stop Nagios monitoring server
# Description: Nagios is is a service monitoring system
# Short-Description: Starts and stops the Nagios monitoring server
# Description: Starts and stops the Nagios monitoring server
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

prefix="@prefix@"
exec_prefix="@exec_prefix@"
exec="@bindir@/nagios"
prog="nagios"
config="@sysconfdir@/nagios.cfg"
pidfile="@lockfile@"
user="nagios"
group="nagios"
checkconfig="true"
ramdiskdir="/var/nagios/ramcache"
use_precached_objects="false"
# Load any extra environment variables for Nagios and its plugins
if test -f /etc/sysconfig/nagios; then
. /etc/sysconfig/nagios
fi

test -e /etc/sysconfig/$prog && . /etc/sysconfig/$prog
# Source function library
# Some *nix do not have an rc.d directory, so do a test first
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
fi

lockfile=/var/lock/subsys/$prog
USE_RAMDISK=${USE_RAMDISK:-0}
prefix=@prefix@
exec_prefix=@exec_prefix@
NagiosBin=@bindir@/nagios
NagiosCfgFile=@sysconfdir@/nagios.cfg
NagiosStatusFile=@localstatedir@/status.dat
NagiosRetentionFile=@localstatedir@/retention.dat
NagiosCommandFile=@localstatedir@/rw/nagios.cmd
NagiosVarDir=@localstatedir@
NagiosRunFile=@lockfile@
NagiosLockDir=/var/lock/subsys
NagiosLockFile=nagios
NagiosCGIDir=@sbindir@
NagiosUser=@nagios_user@
NagiosGroup=@nagios_grp@
checkconfig="true"

# Automate addition of RAMDISK based on environment variables
USE_RAMDISK=${USE_RAMDISK:-0}
if test "$USE_RAMDISK" -ne 0 && test "$RAMDISK_SIZE"X != "X"; then
ramdisk=`mount |grep "$ramdiskdir type tmpfs"`
if [ "$ramdisk"X == "X" ]; then
mkdir -p -m 0755 $ramdiskdir
mount -t tmpfs -o size=${RAMDISK_SIZE}m tmpfs $ramdiskdir
mkdir -p -m 0755 $ramdiskdir/checkresults
chown -R $user:$group $ramdiskdir
mkdir -p -m 0755 ${RAMDISK_DIR}
mount -t tmpfs -o size=${RAMDISK_SIZE}m tmpfs ${RAMDISK_DIR}
mkdir -p -m 0755 ${RAMDISK_DIR}/checkresults
chown -R $NagiosUser:$NagiosGroup ${RAMDISK_DIR}
fi
fi

check_config() {
TMPFILE=$(mktemp /tmp/.configtest.XXXXXXXX)
/sbin/service nagios configtest > "$TMPFILE"
su - $NagiosUser -c "$NagiosBin -vp $NagiosCfgFile" > "$TMPFILE"
WARN=`grep ^"Total Warnings:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`
ERR=`grep ^"Total Errors:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`

Expand All @@ -57,97 +90,204 @@ check_config() {
chmod 0644 /var/run/nagios.configtest
/bin/rm "$TMPFILE"
return 0
elif test "${ERR}" = "0"; then
# We'll write out the errors to a file we can have a
# script watching for
echo "WARNING: Warnings in config files - see log for details: /var/run/nagios.configtest" > /var/run/nagios.configtest
egrep -i "(^warning|^error)" "$TMPFILE" >> /var/run/nagios.configtest
chmod 0644 /var/run/nagios.configtest
/bin/rm "$TMPFILE"
return 0
else
# We'll write out the errors to a file we can have a
# script watching for
echo "WARNING: Errors in config files - see log for details: $TMPFILE" > /var/run/nagios.configtest
echo "ERROR: Errors in config files - see log for details: /var/run/nagios.configtest" > /var/run/nagios.configtest
egrep -i "(^warning|^error)" "$TMPFILE" >> /var/run/nagios.configtest
chmod 0644 /var/run/nagios.configtest
cat "$TMPFILE"
exit 8
fi
}

start() {
test -x $exec || exit 5
test -f $config || exit 6
if test "$checkconfig" = "true"; then
check_config
status_nagios ()
{

if test -x $NagiosCGI/daemonchk.cgi; then
if $NagiosCGI/daemonchk.cgi -l $NagiosRunFile; then
return 0
else
return 1
fi
else
if ps -p $NagiosPID > /dev/null 2>&1; then
return 0
else
return 1
fi
fi
options="-d"
if test "$use_precached_objects" = "true"; then
options="$options -u"
fi
echo -n $"Starting $prog: "
# We need to _make sure_ the precache is there and verified
# Raise priority to make it run better
daemon --user=$user $exec $options $config
retval=$?
echo
test $retval -eq 0 && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $exec
retval=$?
echo
test $retval -eq 0 && rm -f $lockfile
return $retval
return 1
}


restart() {
check_config
checkconfig="true"
stop
start
printstatus_nagios()
{

if status_nagios $1 $2; then
echo "nagios (pid $NagiosPID) is running..."
else
echo "nagios is not running"
fi
}

reload() {
echo -n $"Reloading $prog: "
killproc -p ${pidfile} $exec -HUP
RETVAL=$?
echo

killproc_nagios ()
{

kill $2 $NagiosPID

}

force_reload() {
restart

pid_nagios ()
{

if test ! -f $NagiosRunFile; then
echo "No lock file found in $NagiosRunFile"
exit 1
fi

NagiosPID=`head -n 1 $NagiosRunFile`
}



# Check that nagios exists.
if [ ! -f $NagiosBin ]; then
echo "Executable file $NagiosBin not found. Exiting."
exit 1
fi

# Check that nagios.cfg exists.
if [ ! -f $NagiosCfgFile ]; then
echo "Configuration file $NagiosCfgFile not found. Exiting."
exit 1
fi

# See how we were called.
case "$1" in

start)
status $prog && exit 0
$1
echo -n "Starting nagios:"
if test "$checkconfig" = "true"; then
check_config
fi
if [ $? -eq 0 ]; then
su - $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile"
rm -f $NagiosCommandFile
touch $NagiosRunFile
chown $NagiosUser:$NagiosGroup $NagiosRunFile
$NagiosBin -d $NagiosCfgFile
if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi
echo " done."
exit 0
else
echo "CONFIG ERROR! Start aborted. Check your Nagios configuration."
exit 1
fi
;;

stop)
status $prog|| exit 0
$1
;;
restart)
$1
echo -n "Stopping nagios: "

pid_nagios
killproc_nagios nagios

# now we have to wait for nagios to exit and remove its
# own NagiosRunFile, otherwise a following "start" could
# happen, and then the exiting nagios will remove the
# new NagiosRunFile, allowing multiple nagios daemons
# to (sooner or later) run - John Sellens
#echo -n 'Waiting for nagios to exit .'
for i in 1 2 3 4 5 6 7 8 9 10 ; do
if status_nagios > /dev/null; then
echo -n '.'
sleep 1
else
break
fi
done
if status_nagios > /dev/null; then
echo ''
echo 'Warning - nagios did not exit in a timely manner'
else
echo 'done.'
fi

rm -f $NagiosStatusFile $NagiosRunFile $NagiosLockDir/$NagiosLockFile $NagiosCommandFile
;;
reload)
status $prog || exit 7
$1

status)
pid_nagios
printstatus_nagios nagios
;;
force-reload)
force_reload

checkconfig)
if test "$checkconfig" = "true"; then
printf "Running configuration check..."
check_config
fi

if [ $? -eq 0 ]; then
echo " OK."
else
echo " CONFIG ERROR! Check your Nagios configuration."
exit 1
fi
;;
status)
status $prog

restart)
if test "$checkconfig" = "true"; then
printf "Running configuration check..."
check_config
fi

$0 stop
$0 start

;;
condrestart|try-restart)
status $prog|| exit 0
restart

reload|force-reload)
if test "$checkconfig" = "true"; then
printf "Running configuration check..."
check_config
fi

if test ! -f $NagiosRunFile; then
$0 start
else
pid_nagios
if status_nagios > /dev/null; then
printf "Reloading nagios configuration..."
killproc_nagios nagios -HUP
echo "done"
else
$0 stop
$0 start
fi
fi

;;

configtest)
$nice runuser -s /bin/bash - $user -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config"
RETVAL=$?
su - $NagiosUser -c "$NagiosBin -vp $NagiosCfgFile"

;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
echo "Usage: nagios {start|stop|restart|reload|force-reload|status|checkconfig|configtest}"
exit 1
;;

esac
exit $?

# End of this script
Loading

0 comments on commit 95ee71a

Please sign in to comment.