diff --git a/lib/ynh_lxd b/lib/ynh_lxd index a550188..a48e270 100644 --- a/lib/ynh_lxd +++ b/lib/ynh_lxd @@ -85,6 +85,16 @@ _ynh_lxc_start_and_wait () { LXC_IP=$(lxc exec $1 -- hostname -I | cut -d' ' -f1 | grep -E -o "\<[0-9.]{8,}\>") } +ynh_lxc_swapfiles_clean () { + # 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 $LXC_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' +} + ynh_lxc_snapshot_exists () { local snapname=$1 lxc list --format json \ @@ -98,7 +108,7 @@ ynh_lxc_snapshot_load () { log_debug "Loading snapshot $snapname ..." # Remove swap files before restoring the snapshot. - CLEAN_SWAPFILES + ynh_lxc_swapfiles_clean ynh_lxc_stop $LXC_NAME @@ -111,7 +121,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 - CLEAN_SWAPFILES + ynh_lxc_swapfiles_clean fi ynh_lxc_stop $LXC_NAME diff --git a/lib/ynh_lxd_package_check b/lib/ynh_lxd_package_check index 4e7e646..ca82a18 100644 --- a/lib/ynh_lxd_package_check +++ b/lib/ynh_lxd_package_check @@ -159,7 +159,7 @@ ynh_lxc_pc_snapshot_create () { ynh_lxc_pc_witness_files_check >&2 # Remove swap files to avoid killing the CI with huge snapshots. - CLEAN_SWAPFILES + ynh_lxc_swapfiles_clean ynh_lxc_stop $LXC_NAME @@ -175,16 +175,6 @@ ynh_lxc_pc_snapshot_create () { stop_timer 1 } -CLEAN_SWAPFILES() { - # 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 $LXC_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' -} - RUN_INSIDE_LXC() { lxc exec $LXC_NAME -- "$@" }