remove check_initscripts from standard test suite
[tests.git] / system / template-qemu / qemu-kill-node
index 830d33d..2d84607 100755 (executable)
@@ -1,14 +1,25 @@
 #!/bin/sh
-# $Id$
+#
+# Thierry Parmentelat <thierry.parmentelat@inria.fr>
+# Copyright (C) 2010 INRIA 
+#
 COMMAND=$(basename $0)
 cd $(dirname $0)
+THISNODE=$(basename $(pwd -P) | sed -e s,qemu-,,)
 cd ..
 
+# somehow qemu-system-x86_64 show up in pgrep as qemu-system-x86
+COMMANDS_TO_KILL="qemu qemu-system-x86_64 qemu-system-x86 qemu-kvm"
+
 function usage () {
     echo "Usage: $COMMAND -l"
     echo "  lists current qemu processes"
     echo "usage: $COMMAND hostname"
     echo "  kill qemu instance for that node"
+    echo "usage: $COMMAND this"
+    echo "  kill qemu instance that was started in this directory"
+    echo "usage: $COMMAND"
+    echo "  kill all instances of [$COMMANDS_TO_KILL]"
     exit 1
 }
 
@@ -16,11 +27,14 @@ function list_pids () {
     hostnames="$@"
     if [[ -n "$hostnames" ]] ; then
        for hostname in $hostnames; do
+           [ $hostname == this ] && hostname=$THISNODE
            nodedir=qemu-$hostname
            cat $nodedir/qemu.pid 2> /dev/null
        done
     else
-       pgrep qemu
+       for command in $COMMANDS_TO_KILL; do
+           pgrep -x $command
+       done
     fi
 }
 
@@ -40,12 +54,21 @@ function kill_pids () {
     hostnames="$@"
     if [[ -n "$hostnames" ]] ; then
        for hostname in $hostnames; do
+           [ $hostname == this ] && hostname=$THISNODE
            nodedir=qemu-$hostname
            kill_from_file $nodedir/qemu.pid
        done
     else
-       echo Killing all processes mathing qemu
-       pkill qemu
+       pids=$(list_pids)
+       if [ -n "$pids" ] ; then
+           echo "Killing all processes matching $COMMANDS_TO_KILL"
+           for pid in $pids; do
+               echo Killing $pid
+               kill $pid
+           done
+       else
+           echo "No process found that match $COMMANDS_TO_KILL"
+       fi
     fi
 }
 
@@ -62,7 +85,6 @@ function main () {
     while getopts "lk" opt; do
        case $opt in
            l) OPT_LIST=true ;;
-           k) OPT_GREP=true ;;
            *) usage ;;
        esac
     done