From e41806ae48c09ef8ff2c12a97cd5d1e505f1098b Mon Sep 17 00:00:00 2001 From: nemo Date: Sun, 5 May 2019 17:56:57 +0200 Subject: [PATCH] Check VM is stopped or not before try to create route Sometimes the service try to create route for stopped VM (or template). This case creates a loop and avoid the script to create routes for others VMs while he failed to create route for the stopped VM/template. We met this case with a template... --- inotify-triggered-vm-route-creation.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/inotify-triggered-vm-route-creation.sh b/inotify-triggered-vm-route-creation.sh index c47c8a4..9b526da 100755 --- a/inotify-triggered-vm-route-creation.sh +++ b/inotify-triggered-vm-route-creation.sh @@ -1,9 +1,13 @@ #!/bin/sh inotifywait -q -m --format '%f' -e create /run/qemu-server/ | while read -r vm; do - # Only act if the line is not empty - if [ ${vm} ] && [ "$(echo ${vm} | sed -E 's/[0-9]{3}(\..*)/\1/')" = ".qmp" ]; then - # The sed transforms 100.pid (or .whatever) to 100 - creationRoutesVM $(echo ${vm} | sed -E 's/([0-9]{3})\..*/\1/') - fi + # Only act if the line is not empty + if [ ${vm} ] && [ "$(echo ${vm} | sed -E 's/[0-9]{3}(\..*)/\1/')" = ".qmp" ]; then + # Get VM id ; The sed transforms 100.pid (or .whatever) to 100 + vm_id=$(echo ${vm} | sed -E 's/([0-9]{3})\..*/\1/') + # If vm status is not "stopped" + if [ "$(qm status ${vm_id})" != "status: stopped" ]; then + creationRoutesVM ${vm_id} + fi + fi done