From a7f8a5be133b79e58ddedec46550a118c3894fa0 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 14 Feb 2008 13:15:53 +0000 Subject: [PATCH] fine-grain kill of qemus - new step list_all_qemus --- system/TestMain.py | 3 ++- system/TestPlc.py | 11 +++++++++++ system/qemu_kill.sh | 39 +++++++++++++++++++++++++++++---------- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/system/TestMain.py b/system/TestMain.py index b06f14a..1458b89 100755 --- a/system/TestMain.py +++ b/system/TestMain.py @@ -27,7 +27,8 @@ class TestMain: 'check_tcp' ] other_steps = [ 'fresh_install', 'stop', 'clean_sites', 'clean_nodes', 'clean_slices', 'clean_keys', - 'kill_qemus', 'stop_nodes' , 'db_dump' , 'db_restore', + 'list_all_qemus', 'kill_qemus', 'stop_nodes' , + 'db_dump' , 'db_restore', 'standby_1 through 20', ] default_build_url = "http://svn.planet-lab.org/svn/build/trunk" diff --git a/system/TestPlc.py b/system/TestPlc.py index cb3a11b..5381444 100644 --- a/system/TestPlc.py +++ b/system/TestPlc.py @@ -163,9 +163,20 @@ class TestPlc: TestBox(box).kill_all_qemus() return True + # make this a valid step + def list_all_qemus(self,options): + for (box,nodes) in self.gather_hostBoxes().iteritems(): + # push the script + TestBox(box).copy("qemu_kill.sh") + # this is the brute force version, kill all qemus on that host box + TestBox(box).run("./qemu_kill.sh -l") + return True + # kill only the right qemus def kill_qemus(self,options): for (box,nodes) in self.gather_hostBoxes().iteritems(): + # push the script + TestBox(box).copy("qemu_kill.sh") # the fine-grain version for node in nodes: node.kill_qemu() diff --git a/system/qemu_kill.sh b/system/qemu_kill.sh index ad1a01f..d2c1fc1 100755 --- a/system/qemu_kill.sh +++ b/system/qemu_kill.sh @@ -2,17 +2,36 @@ COMMAND=$(basename $0) hostname=$1; shift -pids="$(ps $(pgrep qemu) | grep $hostname | awk '{print $1;}')" + +# -l option +if [ "$hostname" = "-l" ] ; then + echo $COMMAND - listing qemu processes on $(hostname) + pids="$(pgrep -x qemu) $(pgrep -x start-qemu-node)" + [ -n "$(echo $pids)" ] && ps $pids + exit 0 +fi + +# locate only the actual qemu +qemu_pids="$(pgrep -x start-qemu-node) $(pgrep -x qemu)" + +if [ -z "$(echo $qemu_pids)" ] ; then + echo $COMMAND - no qemu found on $(hostname) + exit 0 +fi + +pids="$(ps $qemu_pids | grep $hostname | awk '{print $1;}')" if [ -z "$pids" ] ; then echo $COMMAND: no qemu instance for $hostname found on $(hostname) -else - echo Killing $pids - kill $pids - sleep 2 - if [ -n "$(ps $pids)" ] ; then - echo Killing -9 $pids - kill -9 $pids - fi - echo Done + exit 0 fi + +echo Killing $pids +kill $pids +(sleep 1; + if ps $pids &> /dev/null ; then + echo still alive - killing -9 $pids + kill -9 $pids + fi ) & +echo Done +exit 0 -- 2.43.0