yunohost_demo/demo_stop.sh

54 lines
2.2 KiB
Bash
Raw Permalink Normal View History

2016-08-12 17:35:14 +02:00
#!/bin/bash
2016-08-13 01:08:44 +02:00
# Stoppe les conteneurs de demo et arrête la config réseau dédiée.
2016-08-12 17:35:14 +02:00
# Récupère le dossier du script
2022-10-13 05:46:46 +02:00
if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(ynh_print_info --message=$PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi
2016-08-12 17:35:14 +02:00
2022-10-13 05:46:46 +02:00
source $script_dir/ynh_lxd
2022-11-05 20:15:50 +01:00
source $script_dir/ynh_lxd_demo
2022-10-13 05:46:46 +02:00
source /usr/share/yunohost/helpers
app=${__APP__:-yunohost_demo}
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
lxc_name1=$(ynh_app_setting_get --app=$app --key=lxc_name1)
lxc_name2=$(ynh_app_setting_get --app=$app --key=lxc_name2)
2016-08-12 17:35:14 +02:00
2022-10-15 22:25:49 +02:00
date | tee -a "$final_path/demo_boot.log" 2>&1
ynh_print_info --message=">> Stopping demo." | tee -a "$final_path/demo_boot.log" 2>&1
2016-09-18 19:23:54 +02:00
if [ "$#" -eq 1 ] && [ "$1" == "-f" ]
then
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Deleting locks and force stopping LXC containers." | tee -a "$final_path/demo_boot.log" 2>&1
2022-10-15 23:36:15 +02:00
ynh_exec_warn_less ynh_secure_remove --file="/var/lib/lxd/$lxc_name1.lock_fileS"
ynh_exec_warn_less ynh_secure_remove --file="/var/lib/lxd/$lxc_name2.lock_fileS"
ynh_exec_warn_less ynh_secure_remove --file="/var/lib/lxd/$lxc_name1.lock_fileU"
ynh_exec_warn_less ynh_secure_remove --file="/var/lib/lxd/$lxc_name2.lock_fileU"
2016-09-18 19:23:54 +02:00
else
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Waiting locks." | tee -a "$final_path/demo_boot.log" 2>&1
2022-10-13 05:46:46 +02:00
while test -e /var/lib/lxd/$lxc_name1.lock_file* || test -e /var/lib/lxd/$lxc_name2.lock_file*; do
2016-09-18 19:23:54 +02:00
sleep 5 # Attend que les conteneur soit libérés par les script upgrade ou switch, le cas échéant.
done
fi
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Stopping LXC containers" | tee -a "$final_path/demo_boot.log" 2>&1
2022-10-15 02:43:00 +02:00
if ynh_lxc_exists --name=$lxc_name1
2022-10-13 05:46:46 +02:00
then
2022-10-15 02:43:00 +02:00
if ! ynh_lxc_is_stopped --name=$lxc_name1
then
2022-10-15 22:47:40 +02:00
ynh_print_info --message="> Stopping $lxc_name1 LXC container" | tee -a "$final_path/demo_boot.log" 2>&1
2022-11-05 20:15:50 +01:00
ynh_lxc_demo_stop --name=$lxc_name1
2022-10-15 02:43:00 +02:00
fi
2016-08-12 17:35:14 +02:00
fi
2022-10-15 02:43:00 +02:00
if ynh_lxc_exists --name=$lxc_name2
2022-10-13 05:46:46 +02:00
then
2022-10-15 02:43:00 +02:00
if ! ynh_lxc_is_stopped --name=$lxc_name2
then
2022-10-15 22:47:40 +02:00
ynh_print_info --message="> Stopping $lxc_name2 LXC container"
2022-11-05 20:15:50 +01:00
ynh_lxc_demo_stop --name=$lxc_name2
2022-10-15 02:43:00 +02:00
fi
2016-08-12 17:35:14 +02:00
fi
2022-10-15 22:25:49 +02:00
date | tee -a "$final_path/demo_boot.log" 2>&1
ynh_print_info --message=">> Finished stopping demo." | tee -a "$final_path/demo_boot.log" 2>&1