From a21fe22b27109a3decd18af9fe021f94aaf3b6dc Mon Sep 17 00:00:00 2001 From: Alexandre LE GALL Date: Sat, 17 Jul 2021 22:25:53 +0200 Subject: [PATCH] =?UTF-8?q?balance-containers:=20g=C3=A9rer=20les=20conten?= =?UTF-8?q?eurs=20arr=C3=AAt=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- balance-containers/run.bash | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/balance-containers/run.bash b/balance-containers/run.bash index de8c072..9d9d578 100755 --- a/balance-containers/run.bash +++ b/balance-containers/run.bash @@ -20,26 +20,33 @@ show_usage() { } move_ct() { + echo -n " move: " + lxc move --target $target $ct 2> /dev/null + [[ $? -eq 0 ]] && echo "success" || echo "failed" +} + +migrate_ct() { echo "- $ct:" echo " target: $ct:" echo " processing:" - # Arrêter - echo -n " stop: " - lxc stop $ct 2> /dev/null - [[ $? -eq 0 ]] && echo "success" || echo "failed" + # SI le conteneur est démarré + if [[ "$(lxc list --columns s --format csv $ct 2> /dev/null)" == "RUNNING" ]]; then + # Arrêter + echo -n " stop: " + lxc stop $ct 2> /dev/null + [[ $? -eq 0 ]] && echo "success" || echo "failed" - # Déplacer - echo -n " move: " - lxc move --target $target $ct 2> /dev/null - [[ $? -eq 0 ]] && echo "success" || echo "failed" + # Déplacer + move_ct - # Démarrer - if [[ $(lxc list --columns s --format csv $ct 2> /dev/null) == "RUNNING" ]]; then + # Démarrer echo -n " start: " lxc start $ct 2> /dev/null [[ $? -eq 0 ]] && echo "success" || echo "failed" else + echo " stop: skipped" + move_ct echo " start: skipped" fi } @@ -60,7 +67,7 @@ case "${1}" in # Traiter le conteneur s'il n'est pas sur l'hôte cible if [[ -z "${host}" ]]; then - move_ct + migrate_ct fi done < $containersList ;; @@ -74,7 +81,7 @@ case "${1}" in # Parcourir la liste de conteneur locaux for line in $(lxc list --columns Ln --format csv 2> /dev/null | grep $(hostname)); do ct=$(echo $line | awk -F',' '{print $2}') - move_ct + migrate_ct done ;; *)