Time to switch

This commit is contained in:
Maniack Crudelis 2016-08-12 18:07:01 +02:00
parent 2776a61252
commit 97847623c3
3 changed files with 17 additions and 3 deletions

View file

@ -11,6 +11,7 @@ DOMAIN=demotest1.nohost.me
YUNO_PWD=admin YUNO_PWD=admin
LXC_NAME1=yunohost_demo1 LXC_NAME1=yunohost_demo1
LXC_NAME2=yunohost_demo2 LXC_NAME2=yunohost_demo2
TIME_TO_SWITCH=30 # En minutes
USER_DEMO=demo USER_DEMO=demo
PASSWORD_DEMO=demo PASSWORD_DEMO=demo
@ -173,3 +174,15 @@ server {
EOF EOF
sudo service nginx reload sudo service nginx reload
# Mise en place du cron de switch
echo | sudo tee /etc/cron.d/demo_switch <<EOF
# Switch des conteneurs toutes les $TIME_TO_SWITCH minutes
*/$TIME_TO_SWITCH * * * * root $script_dir/demo_switch.sh > /dev/null 2>&1
EOF
# Mise en place de HAProxy
# [...]
# Démarrage de la démo
"./$script_dir/demo_start.sh"

View file

@ -30,6 +30,5 @@ echo "> Démarrage de la machine"
sudo lxc-start -n $LXC_NAME -d sudo lxc-start -n $LXC_NAME -d
sleep 3 sleep 3
# Vérifie que la machine a démarré: # Vérifie que la machine a démarré
sudo lxc-ls -f sudo lxc-ls -f

View file

@ -6,11 +6,13 @@ if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$P
PLAGE_IP=$(cat "$script_dir/demo_lxc_build.sh" | grep PLAGE_IP= | cut -d '"' -f2) PLAGE_IP=$(cat "$script_dir/demo_lxc_build.sh" | grep PLAGE_IP= | cut -d '"' -f2)
LXC_NAME1=$(cat "$script_dir/demo_lxc_build.sh" | grep LXC_NAME1= | cut -d '"' -f2) LXC_NAME1=$(cat "$script_dir/demo_lxc_build.sh" | grep LXC_NAME1= | cut -d '"' -f2)
LXC_NAME2=$(cat "$script_dir/demo_lxc_build.sh" | grep LXC_NAME2= | cut -d '"' -f2) LXC_NAME2=$(cat "$script_dir/demo_lxc_build.sh" | grep LXC_NAME2= | cut -d '"' -f2)
TIME_TO_SWITCH=$(cat "$script_dir/demo_lxc_build.sh" | grep TIME_TO_SWITCH= | cut -d '"' -f2)
UPGRADE_DEMO_CONTAINER () { # Démarrage, upgrade et snapshot UPGRADE_DEMO_CONTAINER () { # Démarrage, upgrade et snapshot
MACHINE=$1 MACHINE=$1
# Attend que la machine soit éteinte. # Attend que la machine soit éteinte.
sudo lxc-wait -n $MACHINE -s STOPPED #-t 2000 (Timeout à 33 minutes, puisque le swith est à 30 minutes) TIME_OUT=$(($TIME_TO_SWITCH * 60 + 300)) # Timeout à $TIME_TO_SWITCH +5 minutes, en seconde
sudo lxc-wait -n $MACHINE -s 'STOPPED' -t $TIME_OUT
# Restaure le snapshot # Restaure le snapshot
sudo lxc-snapshot -r snap0 $MACHINE sudo lxc-snapshot -r snap0 $MACHINE