575a291fa3
helpers So we can better trace what failed. notice - just echo to stdout warning - just echo to stderr error - echo to stderr and return false, so trap ERR can catch this fail - like err but call 'exit 1' at the end so if no trap ERR is used it will exit anyway. Change-Id: I5c7b3682fd6c0d81c07c58a5ec965155c7593407 Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-on: https://review.gerrithub.io/392218 Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
67 lines
1.4 KiB
Bash
Executable File
67 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
BASE_DIR=$(readlink -f $(dirname $0))
|
|
[[ -z "$COMMON_DIR" ]] && COMMON_DIR="$(cd $BASE_DIR/../common && pwd)"
|
|
[[ -z "$TEST_DIR" ]] && TEST_DIR="$(cd $BASE_DIR/../../../../ && pwd)"
|
|
|
|
function usage()
|
|
{
|
|
[[ ! -z $2 ]] && ( echo "$2"; echo ""; )
|
|
echo "Shortcut script for shutting down VMs"
|
|
echo "Usage: $(basename $1) [OPTIONS] [VMs]"
|
|
echo
|
|
echo "-h, --help print help and exit"
|
|
echo " --work-dir=WORK_DIR Where to find build file. Must exist. [default: ./..]"
|
|
echo "-a kill/shutdown all running VMs"
|
|
echo "-k kill instead of shutdown"
|
|
exit 0
|
|
}
|
|
optspec='akh-:'
|
|
do_kill=false
|
|
all=false
|
|
|
|
while getopts "$optspec" optchar; do
|
|
case "$optchar" in
|
|
-)
|
|
case "$OPTARG" in
|
|
help) usage $0 ;;
|
|
work-dir=*) TEST_DIR="${OPTARG#*=}" ;;
|
|
*) usage $0 "Invalid argument '$OPTARG'" ;;
|
|
esac
|
|
;;
|
|
h) usage $0 ;;
|
|
k) do_kill=true ;;
|
|
a) all=true ;;
|
|
*) usage $0 "Invalid argument '$OPTARG'"
|
|
esac
|
|
done
|
|
|
|
. $COMMON_DIR/common.sh
|
|
|
|
if $do_kill && [[ $EUID -ne 0 ]]; then
|
|
echo "Go away user come back as root"
|
|
exit 1
|
|
fi
|
|
|
|
if $all; then
|
|
if do_kill; then
|
|
notice "killing all VMs"
|
|
vm_kill_all
|
|
else
|
|
notice "shutting down all VMs"
|
|
vm_shutdown_all
|
|
fi
|
|
else
|
|
shift $((OPTIND-1))
|
|
|
|
if do_kill; then
|
|
notice "INFO: killing VMs: $@"
|
|
for vm in $@; do
|
|
vm_kill $vm
|
|
done
|
|
else
|
|
notice "shutting down all VMs"
|
|
vm_shutdown_all
|
|
fi
|
|
fi
|