balance-containers: gérer les conteneurs arrêté
This commit is contained in:
parent
ab85b5266b
commit
a21fe22b27
@ -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:"
|
||||
|
||||
# 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"
|
||||
move_ct
|
||||
|
||||
# Démarrer
|
||||
if [[ $(lxc list --columns s --format csv $ct 2> /dev/null) == "RUNNING" ]]; then
|
||||
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
|
||||
;;
|
||||
*)
|
||||
|
Loading…
Reference in New Issue
Block a user