--------------080207000106040902050705
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by ace.systemasis.dmz id
mA6BcVHx020284
Hi,
I have done some adjustments to the init script (daemon-init.in, see
attachment). Parameters already defined in nagios.cfg are also defined
in the init script. Thus, changes made to nagios.cfg will be unknown to
the init script. This patch makes the init script read these params from
nagios.cfg instead (ex: log_file, nagios_user, etc).
I have only tested this with ash and bash under Linux, so other
environments need also be tested.
There are still minor cosmetics to take care of though. Unfortunately
that involves the ./configure process, and I am sure there are a lot of
thoughts behind that one, so I do not dare touch it
Consider the following lines:
prefix=3D@prefix@
exec_prefix=3D@exec_prefix@
NagiosBin=3D@bindir@/nagios
NagiosCfgFile=3D@sysconfdir@/nagios.cfg
If you do not explicitly define your paths during the ./configure (ex:
--bindir=3D/usr/local/nagios/bin). The above lines will become:
prefix=3D/usr/local/nagios
exec_prefix=3D${prefix}
NagiosBin=3D${exec_prefix}/bin/nagios
NagiosCfgFile=3D${prefix}/etc/nagios.cfg
Since the first two paths are not needed elsewhere in the init script I
would prefer skip them and get:
NagiosBin=3D/usr/local/nagios/bin/nagios
NagiosCfgFile=3D/usr/local/nagios/etc/nagios.cfg
But for that to happen some tweaking needs to be done in the
configuration process, which currently is out of my reach.
Meanwhile, please feel free to test this patch on as many platforms as
possible.
Take care
/Sven
______________________________________________
Sven-G=F6ran Bergh
Systemasis AB
______________________________________________
--------------080207000106040902050705
Content-Type: text/plain;
name="nagios-init.patch"
Content-Disposition: inline;
filename="nagios-init.patch"
Content-Transfer-Encoding: 7bit
--- daemon-init.in.org 2007-12-13 18:29:48.000000000 +0100
+++ daemon-init.in 2008-11-05 17:14:18.000000000 +0100
@@ -33,7 +33,7 @@
{
if test -x $NagiosCGI/daemonchk.cgi; then
- if $NagiosCGI/daemonchk.cgi -l $NagiosRunFile; then
+ if $NagiosCGI/daemonchk.cgi -l $lock_file; then
return 0
else
return 1
@@ -72,12 +72,21 @@
pid_nagios ()
{
- if test ! -f $NagiosRunFile; then
- echo "No lock file found in $NagiosRunFile"
+ if test ! -f $lock_file; then
+ echo "No lock file found in $lock_file"
exit 1
fi
- NagiosPID=`head -n 1 $NagiosRunFile`
+ NagiosPID=`head -n 1 $lock_file`
+}
+
+
+get_nagios_param() {
+
+ [ "${1}" ] || return 1
+
+ awk -F= "/\\\`[[:space:]]*$1[[:space:]]*=/ {print \$2; exit;}" ${NagiosCfgFile} \
+ | awk '{print $1}'
}
@@ -93,17 +102,8 @@
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@
-
# Check that nagios exists.
if [ ! -f $NagiosBin ]; then
@@ -116,7 +116,21 @@
echo "Configuration file $NagiosCfgFile not found. Exiting."
exit 1
fi
-
+
+# Get these values from the main configurtion file ${NagiosCfgFile}
+NagiosParams="log_file status_file state_retention_file command_file lock_file \
+ nagios_user nagios_group"
+
+for param in ${NagiosParams}; do
+ value=$( get_nagios_param $param )
+ eval export \$param=$value
+
+ if [ -z "$value" ]; then
+ echo "Cannot read parameter $param from ${NagiosCfgFile}. Exiting."
+ exit 1
+ fi
+done
+
# See how we were called.
case "$1" in
@@ -124,10 +138,10 @@
echo -n "Starting nagios:"
$NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
if [ $? -eq 0 ]; then
- su - $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile"
- rm -f $NagiosComman
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]