1
0

balance-containers: gérer les conteneurs arrêté

This commit is contained in:
pulsar89.5 2021-07-17 22:25:53 +02:00
parent ab85b5266b
commit a21fe22b27

View File

@ -20,26 +20,33 @@ show_usage() {
} }
move_ct() { move_ct() {
echo -n " move: "
lxc move --target $target $ct 2> /dev/null
[[ $? -eq 0 ]] && echo "success" || echo "failed"
}
migrate_ct() {
echo "- $ct:" echo "- $ct:"
echo " target: $ct:" echo " target: $ct:"
echo " processing:" echo " processing:"
# SI le conteneur est démarré
if [[ "$(lxc list --columns s --format csv $ct 2> /dev/null)" == "RUNNING" ]]; then
# Arrêter # Arrêter
echo -n " stop: " echo -n " stop: "
lxc stop $ct 2> /dev/null lxc stop $ct 2> /dev/null
[[ $? -eq 0 ]] && echo "success" || echo "failed" [[ $? -eq 0 ]] && echo "success" || echo "failed"
# Déplacer # Déplacer
echo -n " move: " move_ct
lxc move --target $target $ct 2> /dev/null
[[ $? -eq 0 ]] && echo "success" || echo "failed"
# Démarrer # Démarrer
if [[ $(lxc list --columns s --format csv $ct 2> /dev/null) == "RUNNING" ]]; then
echo -n " start: " echo -n " start: "
lxc start $ct 2> /dev/null lxc start $ct 2> /dev/null
[[ $? -eq 0 ]] && echo "success" || echo "failed" [[ $? -eq 0 ]] && echo "success" || echo "failed"
else else
echo " stop: skipped"
move_ct
echo " start: skipped" echo " start: skipped"
fi fi
} }
@ -60,7 +67,7 @@ case "${1}" in
# 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 if [[ -z "${host}" ]]; then
move_ct migrate_ct
fi fi
done < $containersList done < $containersList
;; ;;
@ -74,7 +81,7 @@ case "${1}" in
# Parcourir la liste de conteneur locaux # Parcourir la liste de conteneur locaux
for line in $(lxc list --columns Ln --format csv 2> /dev/null | 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}') ct=$(echo $line | awk -F',' '{print $2}')
move_ct migrate_ct
done done
;; ;;
*) *)