diff --git a/lib/ynh_lxd b/lib/ynh_lxd index b89962b..822b0bd 100644 --- a/lib/ynh_lxd +++ b/lib/ynh_lxd @@ -138,14 +138,27 @@ _ynh_lxc_start_and_wait () { LXC_IP=$(lxc exec $name -- hostname -I | cut -d' ' -f1 | grep -E -o "\<[0-9.]{8,}\>") } +# Clean the swapfiles of an LXC container +# +# usage: ynh_lxc_swapfiles_clean --name=name +# | arg: -n, --name= - name of the LXC +# +# Requires YunoHost version *.*.* or higher. ynh_lxc_swapfiles_clean () { + # Declare an array to define the options of this helper. + local legacy_args=n + local -A args_array=([n]=name=) + local name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + # Restart it if needed - if [ "$(lxc info $LXC_NAME | grep Status | awk '{print tolower($2)}')" != "running" ]; then - lxc start $LXC_NAME - _ynh_lxc_start_and_wait --name=$LXC_NAME + if [ "$(lxc info $name | grep Status | awk '{print tolower($2)}')" != "running" ]; then + lxc start $name + _ynh_lxc_start_and_wait --name=$name fi - lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do swapoff $swapfile; done' - lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do rm -f $swapfile; done' + lxc exec $name -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do swapoff $swapfile; done' + lxc exec $name -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do rm -f $swapfile; done' } ynh_lxc_snapshot_exists () { @@ -161,7 +174,7 @@ ynh_lxc_snapshot_load () { log_debug "Loading snapshot $snapname ..." # Remove swap files before restoring the snapshot. - ynh_lxc_swapfiles_clean + ynh_lxc_swapfiles_clean --name=$LXC_NAME ynh_lxc_stop --name=$LXC_NAME @@ -174,7 +187,7 @@ ynh_lxc_reset () { # If the container exists if lxc info $LXC_NAME >/dev/null 2>/dev/null; then # Remove swap files before deletting the continer - ynh_lxc_swapfiles_clean + ynh_lxc_swapfiles_clean --name=$LXC_NAME fi ynh_lxc_stop --name=$LXC_NAME diff --git a/lib/ynh_lxd_package_check b/lib/ynh_lxd_package_check index c368c06..eb7a190 100644 --- a/lib/ynh_lxd_package_check +++ b/lib/ynh_lxd_package_check @@ -255,7 +255,7 @@ ynh_lxc_pc_snapshot_create () { ynh_lxc_pc_witness_files_check --name=$name >&2 # Remove swap files to avoid killing the CI with huge snapshots. - ynh_lxc_swapfiles_clean + ynh_lxc_swapfiles_clean --name=$name ynh_lxc_stop --name=$name