From 7223aa2fc6d5e6aee5814070fc4cf53bd0a0aafc Mon Sep 17 00:00:00 2001 From: Alexandre LE GALL Date: Fri, 16 Jul 2021 17:29:36 +0200 Subject: [PATCH] =?UTF-8?q?balance-containers:=20indiquer=20vers=20quel=20?= =?UTF-8?q?h=C3=B4te=20est=20d=C3=A9place=20le=20conteneur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- balance-containers/run.bash | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/balance-containers/run.bash b/balance-containers/run.bash index 343494e..ddd458f 100755 --- a/balance-containers/run.bash +++ b/balance-containers/run.bash @@ -20,14 +20,24 @@ show_usage() { } move_ct() { -# echo "lxc move --target $target $ct" + echo "$ct:" + echo " target: $ct:" + echo " processing:" - # Arrêter le conteneur - lxc stop $ct; + # Arrêter + echo -n " stop: " + lxc stop $ct 2> /dev/null + [[ $? -eq 0 ]] && echo "success" || echo "failed" - # Déplacer et démarrer le conteneur - lxc move --target $target $ct &&\ - lxc start $ct + # Déplacer + echo -n " move: " + lxc move --target $target $ct 2> /dev/null + [[ $? -eq 0 ]] && echo "success" || echo "failed" + + # Démarrer + echo -n " start: " + lxc start $ct 2> /dev/null + [[ $? -eq 0 ]] && echo "success" || echo "failed" } # Boucler sur les arguments @@ -42,9 +52,9 @@ case "${1}" in ct=$(echo $line | awk -F',' '{print $2}') # Récupérer l'hôte courrant - host=$(lxc list --columns Ln --format csv $ct | grep $target) + host=$(lxc list --columns Ln --format csv $ct 2> /dev/null | grep $target) - # Traiter le conteneur s il n'est pas sur l'hôte cible + # Traiter le conteneur s'il n'est pas sur l'hôte cible if [[ -z "${host}" ]]; then move_ct fi @@ -58,7 +68,7 @@ case "${1}" in target="${2}" # Parcourir la liste de conteneur locaux - for line in $(lxc list --columns Ln --format csv | grep $(hostname)); do + for line in $(lxc list --columns Ln --format csv 2> /dev/null | grep $(hostname)); do ct=$(echo $line | awk -F',' '{print $2}') move_ct done