diff -up ./daemon-init.in.fix_el6_init ./daemon-init.in
--- ./daemon-init.in.fix_el6_init 2017-08-24 17:43:48.000000000 -0400
+++ ./daemon-init.in 2017-11-20 15:49:22.689188040 -0500
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# chkconfig: 345 99 01
+# chkconfig: - 99 01
# description: Nagios network monitor
# processname: nagios
# File : nagios
@@ -91,12 +91,12 @@ check_config ()
echo "ERROR: Could not delete '$NagiosCfgtestFile'"
exit 8
fi
- if ! su $NagiosUser -c "touch $NagiosCfgtestFile"; then
+ if ! su $NagiosUser -c "touch $NagiosCfgtestFile" -s /bin/sh ; then
echo "ERROR: Could not create or update '$NagiosCfgtestFile'"
exit 8
fi
- TMPFILE=$(mktemp /tmp/.configtest.XXXXXXXX)
+ TMPFILE=$(mktemp $NagiosCfgtestFile.XXX )
$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`
@@ -134,28 +134,47 @@ status_nagios ()
printstatus_nagios ()
{
- if status_nagios; then
+ status_nagios $1 $2
+ RETVAL=$?
+ if [ $RETVAL = 0 ]; then
echo "nagios (pid $NagiosPID) is running..."
else
echo "nagios is not running"
fi
+ return $RETVAL
}
killproc_nagios ()
{
+ if test ! -f $NagiosRunFile; then
+ echo "No lock file found in $NagiosRunFile"
+
kill -s "$1" $NagiosPID
+ fi
}
pid_nagios ()
{
- if test ! -f $NagiosRunFile; then
- echo "No lock file found in $NagiosRunFile"
- exit 1
- fi
-
- NagiosPID=`head -n 1 $NagiosRunFile`
+ if test ! -f $NagiosRunFile; then
+ echo "No lock file found in $NagiosRunFile"
+ exit 1
+ fi
+
+ export NagiosPID=`head -n 1 $NagiosRunFile`
+ if [[ -z "$NagiosPID" ]]; then
+ echo "No usable PID found in $NagiosRunFile"
+ exit 1
+ fi
+
+ regex='^[0-9]+$'
+ if ! [[ $NagiosPID =~ $regex ]]; then
+ echo "PID not number found in $NagiosRunFile"
+ exit 1
+ fi
+
}
+
remove_commandfile ()
{
# Removing a stalled command file, while there are processes trying/waiting to write into it,
@@ -165,11 +183,14 @@ remove_commandfile ()
# In order for the dd to not deadlock when there is no writing process, it is executed in the
# background in a subshell together with an empty echo to have at least one writing process.
- # see http://unix.stackexchange.com/questions/335406/opening-named-pipe-blocks-forever-if-pipe-is-deleted-without-being-connected
+ # see
+ # http://unix.stackexchange.com/questions/335406/opening-named-pipe-blocks-forever-if-pipe-is-deleted-without-being-connected
+ # a second & is needed to make this work reliably as we need to
+ # background both for the sub-shell to end.
- if [ -p $NagiosCommandFile ]; then
+ if [ -p $NagiosCommandFile ]; then
mv -f $NagiosCommandFile $NagiosCommandFile~
- (dd if=$NagiosCommandFile~ count=0 2>/dev/null & echo -n "" >$NagiosCommandFile~)
+ (dd if=$NagiosCommandFile~ count=0 2>/dev/null & echo -n "" >$NagiosCommandFile~ &)
fi
rm -f $NagiosCommandFile $NagiosCommandFile~
@@ -207,7 +228,7 @@ case "$1" in
fi
fi
- su $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile"
+ su $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile" -s /bin/sh
remove_commandfile
touch $NagiosRunFile
$NagiosBin -d $NagiosCfgFile
@@ -251,6 +272,7 @@ case "$1" in
status)
pid_nagios
printstatus_nagios
+ exit $?
;;
checkconfig)
@@ -305,6 +327,7 @@ case "$1" in
*)
echo "Usage: nagios {start|stop|restart|reload|force-reload|status|checkconfig|configtest}"
exit 1
+ exit 2
;;
esac