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() {
|
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:"
|
||||||
|
|
||||||
# Arrêter
|
# SI le conteneur est démarré
|
||||||
echo -n " stop: "
|
if [[ "$(lxc list --columns s --format csv $ct 2> /dev/null)" == "RUNNING" ]]; then
|
||||||
lxc stop $ct 2> /dev/null
|
# Arrêter
|
||||||
[[ $? -eq 0 ]] && echo "success" || echo "failed"
|
echo -n " stop: "
|
||||||
|
lxc stop $ct 2> /dev/null
|
||||||
|
[[ $? -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
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
Loading…
Reference in New Issue
Block a user