[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: rewrite icinga/ido2db initscript, not only depending on lockfile and removing it if start fails

git at icinga.org git at icinga.org
Tue May 25 12:46:53 CEST 2010


Module: icinga-core
Branch: mfriedrich/core
Commit: 055f4979dfa8cb3204820459a44ef081edfa26ec
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=055f4979dfa8cb3204820459a44ef081edfa26ec

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Tue May 25 00:59:06 2010 +0200

rewrite icinga/ido2db initscript, not only depending on lockfile and removing it if start fails

1/ ido2db initscript was too dependant on the lockfile existing or not,
the routines now are the same as icinga core and it works flawlessly.
also if ido2db does not stop in a timely manner, the lockfile does not
get removed now.

2/ ido2db and icinga might fail after starting them. in this case the lockfile
and everything else needs to be removed. this is now done by checking on the status
and if no process running, showing an error and removing everything like the process
was stopped.

fixes #447
fixes #448

---

 Changelog      |    3 ++
 daemon-init.in |   12 +++++++-
 rc.ido2db.in   |   73 +++++++++++++++++++++++++++++--------------------------
 3 files changed, 51 insertions(+), 37 deletions(-)

diff --git a/Changelog b/Changelog
index e4f3dc9..5ea8e88 100644
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,7 @@ Icinga 1.0.x Change Log
 
 ENHANCEMENTS
 * core: init script shows config errors option; don't remove pidfile if icinga did not stop in a timely manner
+* core: check if icinga running after init script 'start', if not, show error and remove lockfile
 * core: add in sync retention facility (Ton Voon, Opsera Ltd)
 * core: add new is_volatile setting of 2 for services, which respects the re-notification interval for notifications (Ton Voon)
 * core: add Icinga option -S functions much like -s but will dump the entire scheduling queue is it would run, 
@@ -21,6 +22,8 @@ ENHANCEMENTS
 * idoutils: Spread the list of linked lists thinner (extend objects hash slots) (Opsera Ltd)
 * idoutils: change select * into select [*_]id if unused results
 * idoutils: add syslog output, if ido2db is unable to do initial db query
+* idoutils: rewrite initscript not only depending on lockfile
+* idoutils: check if ido2db running after init script 'start', if not, show error and remove lockfile 
 
 * config: add trailing slash in apache config for html dir
 
diff --git a/daemon-init.in b/daemon-init.in
index 4755a93..6626d2e 100644
--- a/daemon-init.in
+++ b/daemon-init.in
@@ -84,7 +84,7 @@ pid_icinga ()
 {
 
 	if test ! -f $IcingaRunFile; then
-		echo "No lock file found in $IcingaRunFile"
+		echo "Icinga not running. No lock file found in $IcingaRunFile"
 		exit 1
 	fi
 
@@ -166,7 +166,15 @@ case "$1" in
 		chown $IcingaUser:$IcingaGroup $IcingaRunFile
 		$IcingaBin -d $IcingaCfgFile
 		if [ -d $IcingaLockDir ]; then touch $IcingaLockDir/$IcingaLockFile; fi
-		echo "Starting icinga done."
+
+                #check if icinga did bailout because of initialization errors
+		pid_icinga
+                if status_icinga > /dev/null; then
+                        echo " done."
+                else
+                        echo " failed. Please check the log!"
+			rm -f $IcingaStatusFile $IcingaRunFile $IcingaLockDir/$IcingaLockFile $IcingaCommandFile
+                fi
 		exit 0
 		;;
 
diff --git a/rc.ido2db.in b/rc.ido2db.in
index 2dbe441..b9da860 100644
--- a/rc.ido2db.in
+++ b/rc.ido2db.in
@@ -41,16 +41,15 @@
 status_ido2db ()
 {
 
-	pid_ido2db
-
 	if ps -p $Ido2dbPID > /dev/null 2>&1; then
 		return 0
 	else
-		if test -f $Ido2dbLockDir/$Ido2dbLockFile; then
-       			return 2
-		else
-			return 1
-		fi
+		return 1
+		#if test -f $Ido2dbLockDir/$Ido2dbLockFile; then
+       		#	return 2
+		#else
+		#	return 1
+		#fi
         fi
 
         return 1
@@ -71,7 +70,7 @@ printstatus_ido2db()
 killproc_ido2db ()
 {
 
-	kill $2 $1
+	kill $2 $Ido2dbPID
 
 }
 
@@ -80,22 +79,21 @@ pid_ido2db ()
 {
 
 	if test ! -f $Ido2dbRunFile; then
-		echo "PID file $Ido2dbRunFile not found"
+		echo "ido2db not running. PID file $Ido2dbRunFile not found"
 		exit 1
 	fi
 
 	Ido2dbPID=`head -n 1 $Ido2dbRunFile`
-	return 0
 }
 
-checkpid_ido2db() {
-        local i
-
-        for i in $* ; do
-                [ -d "/proc/$i" ] && return 0
-        done
-        return 1
-}
+#checkpid_ido2db() {
+#        local i
+#
+#        for i in $* ; do
+#                [ -d "/proc/$i" ] && return 0
+#        done
+#        return 1
+#}
 
 
 
@@ -139,8 +137,11 @@ fi
 case "$1" in
 
 	start)
-		if [ -f $Ido2dbRunFile ]; then
-			echo "$servicename already started (found pidfile $Ido2dbRunFile)..."
+		#check if ido2db is already running
+		$0 status > /dev/null
+		if [ $? -eq 0 ]; then
+			pid_ido2db
+			echo "$servicename is already running. PID: $Ido2dbPID"
 			exit 1
 		fi
 		echo -n "Starting $servicename:"
@@ -148,22 +149,23 @@ case "$1" in
 		chown $Ido2dbUser:$Ido2dbGroup $Ido2dbRunFile
 		$Ido2dbBin -c $Ido2dbCfgFile
 		if [ -d $Ido2dbLockDir ]; then touch $Ido2dbLockDir/$Ido2dbLockFile; fi
-		echo " done."
+	
+		#check if ido2db did bailout because of initialization errors
+		pid_ido2db
+		if status_ido2db > /dev/null; then
+			echo " done."
+		else
+			echo " failed. Please check the log!"
+			rm -f $Ido2dbStatusFile $Ido2dbRunFile $Ido2dbLockDir/$Ido2dbLockFile $Ido2dbCommandFile
+		fi
 		exit 0
 		;;
 
 	stop)
-		status_ido2db
-		if ! [ $? -eq 0 ]; then
-			echo "$servicename was not running... could not stop"
-			exit 1
-		fi
 		echo -n "Stopping $servicename: "
 
-		# Set up $Ido2dbPID, exist if it does not work
 		pid_ido2db 
-		# Kill the process
-		killproc_ido2db $Ido2dbPID
+		killproc_ido2db ido2db
 
  		# now we have to wait for ido2db to exit and remove its
  		# own Ido2dbRunFile, otherwise a following "start" could
@@ -171,25 +173,26 @@ case "$1" in
  		# new Ido2dbRunFile, allowing multiple ido2db daemons
  		# to (sooner or later) run - John Sellens
  		for i in 1 2 3 4 5 6 7 8 9 10 ; do
- 		    if checkpid_ido2db $Ido2dbPID > /dev/null; then
+ 		    if status_ido2db > /dev/null; then
  			echo -n '.'
  			sleep 1
  		    else
  			break
  		    fi
  		done
- 		if checkpid_ido2db $Ido2dbPID > /dev/null; then
+ 		if status_ido2db > /dev/null; then
  		    echo ''
- 		    echo 'Warning - $servicename did not exit in a timely manner'
+ 		    echo "Warning - $servicename did not exit in a timely manner"
  		else
- 		    echo 'done.'
+ 		    echo "done."
+		    rm -f $Ido2dbStatusFile $Ido2dbRunFile $Ido2dbLockDir/$Ido2dbLockFile $Ido2dbCommandFile
  		fi
 
-		rm -f $Ido2dbStatusFile $Ido2dbRunFile $Ido2dbLockDir/$Ido2dbLockFile $Ido2dbCommandFile
 		;;
 
         status)
-		printstatus_ido2db
+		pid_ido2db
+		printstatus_ido2db ido2db
                 ;;
 
 	restart)





More information about the icinga-checkins mailing list