Xymon Mailing List Archive search

[patch] debian hobbit client init script

3 messages in this thread

list Gildas le Nadan · Mon, 20 Nov 2006 15:22:39 +0000 ·
Hi,

As I said earlier we want the hobbit client script to remove the 
temporary files and kill the rogue processes when stopped, mainly so the 
hobbit-client installation/upgrade process through cfengine runs smoothly.

Here is a patch to the debian hobbit client init script to do the 
following actions when the hobbit client is stopped:
- remove the /var/run/hobbitclient-runtime.cfg file
- kill the unwanted vmstat processes that were left running
- remove any files owned by hobbit from /tmp

Patch may be applied on 4.2.0 with allinone patch applied, using:

  cd hobbit-4.2.0
  patch -p1 < /path/to/patch/hobbitclient_clean.patch

Comments to help polishing this solution are more than welcome!

Cheers
Gildas
list Charles Goyard · Mon, 20 Nov 2006 16:32:50 +0100 ·
Hi all,

you need the DMNOPTS when stopping/restarting, or it fails if you force
the hostname.

(patch attached)

-- 
Charles Goyard - user-98f9625a7a59@xymon.invalid - (+33) 1 45 38 01 31
-------------- next part --------------
diff -Naur hobbit-4.2.0-allinone/debian/hobbit-client.init hobbit-4.2.0-cfengine/debian/hobbit-client.init
--- hobbit-4.2.0-allinone/debian/hobbit-client.init	2006-08-09 21:10:17.000000000 +0100
+++ hobbit-4.2.0-cfengine/debian/hobbit-client.init	2006-11-20 13:48:29.757748327 +0000
@@ -26,14 +26,33 @@
 	exit 1
 fi
 
-set $HOBBITSERVERS
-if [ $# -eq 1 ]; then
-	echo "BBDISP=\"$HOBBITSERVERS\"" >/var/run/hobbitclient-runtime.cfg
-	echo "BBDISPLAYS=\"\"" >>/var/run/hobbitclient-runtime.cfg
-else
-	echo "BBDISP=\"0.0.0.0\"" >/var/run/hobbitclient-runtime.cfg
-	echo "BBDISPLAYS=\"$HOBBITSERVERS\"" >>/var/run/hobbitclient-runtime.cfg
-fi
+set_servers () {
+	set $HOBBITSERVERS
+	if [ $# -eq 1 ]; then
+		echo "BBDISP=\"$HOBBITSERVERS\"" >/var/run/hobbitclient-runtime.cfg
+		echo "BBDISPLAYS=\"\"" >>/var/run/hobbitclient-runtime.cfg
+	else
+		echo "BBDISP=\"0.0.0.0\"" >/var/run/hobbitclient-runtime.cfg
+		echo "BBDISPLAYS=\"$HOBBITSERVERS\"" >>/var/run/hobbitclient-runtime.cfg
+	fi
+}
• +kill_rogue_vmstat () {
+	for VMSTAT_PID in `ps -U hobbit | grep vmstat | awk '{print $1}'`; do
+		kill ${VMSTAT_PID}
+	done
+	# wait for the nohup parent shell script to finish
+	sleep 1
+}
• +clean_var_run () {
+	rm /var/run/hobbitclient-runtime.cfg >/dev/null 2>&1
+}
• +clean_tmp () {
+	# it's not the cleanest but debian client use /tmp as BBTMP anyway
+	find /tmp -user hobbit -exec rm -rf \{} \; >/dev/null 2>&1
+}
 
 if [ "$CLIENTHOSTNAME" != "" ]; then
 	DMNOPTS="${DMNOPTS} --hostname=${CLIENTHOSTNAME}"
@@ -47,17 +66,23 @@
 case "$CMD" in
   start)
 	echo -n "Starting $DESC: "
+	set_servers
 	su -c "$DAEMON $DMNOPTS start" - hobbit
 	echo "$NAME."
 	;;
   stop)
 	echo -n "Stopping $DESC: "
 	su -c "$DAEMON $DMNOPTS stop" - hobbit
+	kill_rogue_vmstat
+	clean_tmp
+	clean_var_run
 	echo "$NAME."
 	;;
   restart|force-reload)
 	echo -n "Restarting $DESC: "
 	su -c "$DAEMON $DMNOPTS stop" - hobbit
+	kill_rogue_vmstat
+	clean_tmp
 	su -c "$DAEMON $DMNOPTS start" - hobbit
 	echo "$NAME."
 	;;
list Gildas le Nadan · Mon, 20 Nov 2006 15:42:27 +0000 ·
quoted from Charles Goyard
Charles Goyard wrote:
Hi all,

you need the DMNOPTS when stopping/restarting, or it fails if you force
the hostname.

(patch attached)
Hum, My patch was not removing it from the original file, unless I'm 
wrong (the patch was im 2 hunks)

Thanks for the review anyway ;)

Cheers,
Gildas