--- 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 $NagiosCommandFile
-			touch $NagiosRunFile
-			chown $NagiosUser:$NagiosGroup $NagiosRunFile
+			su - $nagios_user -c "touch $log_file $state_retention_file"
+			rm -f $command_file
+			touch $lock_file
+			chown $nagios_user:$nagios_group $lock_file
 			$NagiosBin -d $NagiosCfgFile
 			if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi
 			echo " done."
@@ -145,9 +159,9 @@
 		killproc_nagios nagios
 
  		# now we have to wait for nagios to exit and remove its
- 		# own NagiosRunFile, otherwise a following "start" could
+ 		# own lock_file, otherwise a following "start" could
  		# happen, and then the exiting nagios will remove the
- 		# new NagiosRunFile, allowing multiple nagios daemons
+ 		# new lock_file, 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
@@ -165,7 +179,7 @@
  		    echo 'done.'
  		fi
 
-		rm -f $NagiosStatusFile $NagiosRunFile $NagiosLockDir/$NagiosLockFile $NagiosCommandFile
+		rm -f $status_file $lock_file $NagiosLockDir/$NagiosLockFile $command_file
 		;;
 
 	status)
@@ -202,7 +216,7 @@
 		$NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
 		if [ $? -eq 0 ]; then
 			echo "done."
-			if test ! -f $NagiosRunFile; then
+			if test ! -f $lock_file; then
 				$0 start
 			else
 				pid_nagios

