From 50f8c5e316d12c9c6f4a7512b61a9528bc9dc1ff Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 19 Dec 2023 01:57:31 +0100 Subject: [PATCH] Make system_is_inside_container a proper bash function --- conf/systemd.service | 2 +- scripts/_common.sh | 12 ++++++++---- scripts/config | 4 ++-- scripts/install | 2 +- scripts/remove | 2 +- scripts/restore | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 05f78ac..6e9ddf0 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -5,7 +5,7 @@ Wants=network-online.target [Service] User=__APP__ -Environment='RUST_LOG=garage=info' 'VIRTUALISATION=__SYSTEM_IS_INSIDE_CONTAINER__' 'RUST_BACKTRACE=1' +Environment='RUST_LOG=garage=info' 'VIRTUALISATION=__SYSTEM_IS_INSIDE_CONTAINER_BOOL__' 'RUST_BACKTRACE=1' ExecStartPre=+__INSTALL_DIR__/mount_disk.sh ExecStart=__INSTALL_DIR__/garage -c __INSTALL_DIR__/garage.toml server ExecStopPost=+__INSTALL_DIR__/umount_disk.sh diff --git a/scripts/_common.sh b/scripts/_common.sh index 74aedcc..cbadbf1 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,13 +6,17 @@ GARAGE_VERSION="0.9.0" -if systemd-detect-virt -c -q +system_is_inside_container() { + systemd-detect-virt -c -q +} + +if system_is_inside_container then - system_is_inside_container="true" # used to comment systemd isolation to allow mount disk + system_is_inside_container_bool="true" comment_if_system_is_inside_container="#" else - system_is_inside_container="false" + system_is_inside_container_bool="false" comment_if_system_is_inside_container="" fi @@ -22,7 +26,7 @@ fi garage_connect() { local command="$1" - local peer="$2" + local peer="$2" # connect to cluster $command node connect "$peer" sleep 2 diff --git a/scripts/config b/scripts/config index ebe614c..0e8b3bf 100644 --- a/scripts/config +++ b/scripts/config @@ -7,7 +7,7 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -if [[ "$system_is_inside_container" == "true" ]] +if system_is_inside_container then nbd_index=$(cat $data_dir/nbd_index) fi @@ -15,7 +15,7 @@ fi command="$install_dir/garage -c $install_dir/garage.toml" set__weight() { - if [[ "$system_is_inside_container" == "true" ]] + if system_is_inside_container then systemctl stop $app old_weight="$(ynh_app_setting_get --app=$app --key=weight)" diff --git a/scripts/install b/scripts/install index 9478dfc..74da92b 100755 --- a/scripts/install +++ b/scripts/install @@ -79,7 +79,7 @@ chown $app:$app "$install_dir/garage.toml" #================================================= ynh_script_progression --message="Creating a data directory..." --weight=5 -if [[ "$system_is_inside_container" == "true" ]] +if system_is_inside_container then ynh_print_warn --message="This may take time regarding disk size..." diff --git a/scripts/remove b/scripts/remove index c7210aa..d138caf 100755 --- a/scripts/remove +++ b/scripts/remove @@ -40,7 +40,7 @@ ynh_remove_systemd_config # Remove the app-specific logrotate config ynh_remove_logrotate -if [[ "$system_is_inside_container" == "true" ]] +if system_is_inside_container then ynh_script_progression --message="Umount virtual disk..." diff --git a/scripts/restore b/scripts/restore index 37f1510..cef70ba 100755 --- a/scripts/restore +++ b/scripts/restore @@ -24,7 +24,7 @@ chown -R $app:$app "$install_dir" #================================================= ynh_script_progression --message="Restoring the data directory..." -if [[ "$system_is_inside_container" == "true" ]] +if system_is_inside_container then # to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size. qemu-img create -f qcow2 $data_dir/garage_data.qcow2 "$weight"G