diff options
author | Dominique Martinet <asmadeus@codewreck.org> | 2012-11-17 10:59:33 +0100 |
---|---|---|
committer | Dominique Martinet <asmadeus@codewreck.org> | 2012-11-20 13:39:26 +0100 |
commit | 49d727b03d9a22f1e8f1b4ccba1aa73fac8536ea (patch) | |
tree | 85ac4cda7a240bc29ceec653f6c12a27fab9cf84 | |
parent | 796bf27d9a3677a547d41ae1f34e126580f4597a (diff) |
Keep a pid file if in error state, so it can't be started again
-rwxr-xr-x | kvm-wrapper.sh | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/kvm-wrapper.sh b/kvm-wrapper.sh index 9515060..0e7745d 100755 --- a/kvm-wrapper.sh +++ b/kvm-wrapper.sh @@ -21,8 +21,12 @@ function fail_exit () echo -ne '\n' echo -e "$1" [[ -n "$STY" ]] && ( + local USE_PID_FILE="" + test_exist "$PID_FILE" || USE_PID_FILE="true" + [[ -n "$USE_PID_FILE" ]] && echo "error" > "$PID_FILE" echo "Press ^D (EOF) or enter to exit" read + [[ -n "$USE_PID_FILE" ]] && rm -f "$PID_FILE" ) echo "Exiting." exit 1 @@ -393,7 +397,11 @@ function kvm_status_vm () kvm_init_env "$1" test_exist "$PID_FILE" || fail_exit "Error : $VM_NAME doesn't seem to be running." - kvm_status_from_pid `cat "$PID_FILE"` + local VM_PID="`cat "$PID_FILE"`" + + [[ "$VM_PID" = "error" ]] \ + && echo "VM $VM_NAME is in error state, attach it for more info" \ + || kvm_status_from_pid "$VM_PID" } function kvm_status () @@ -407,8 +415,15 @@ function kvm_status () for KVM_CLUSTER_NODE in `ls -1 $PID_DIR/*-vm.pid|cut -d: -f1|sed -e 's:.*/::'|uniq` do - echo "servers on $KVM_CLUSTER_NODE:" - kvm_status_from_pid `cat $PID_DIR/$KVM_CLUSTER_NODE\:*-vm.pid` + echo "VMs on $KVM_CLUSTER_NODE:" + kvm_status_from_pid `cat "$PID_DIR/$KVM_CLUSTER_NODE:"*-vm.pid|grep -v error` + + echo + + grep -l error "$PID_DIR/$KVM_CLUSTER_NODE:"*-vm.pid | sed -e 's!.*:\(.*\)-vm.pid!\1!' | while read VM_NAME; do + echo "VM $VM_NAME is in error state, attach it for more info" + echo + done done fi } @@ -645,7 +660,11 @@ function kvm_list () kvm_init_env `basename "${file%"-vm"}"` if [[ -z "$1" || "$1" == "$KVM_CLUSTER_NODE" ]]; then local VM_STATUS="Halted" - test_exist "$PID_FILE" && VM_STATUS="Running" + test_exist "$PID_FILE" && { + [[ "$(cat "$PID_FILE")" = "error" ]] \ + && VM_STATUS="Error" \ + || VM_STATUS="Running" + } printf "\t%-20s\t$VM_STATUS\ton ${KVM_CLUSTER_NODE:-local}\n" "$VM_NAME" fi done |