diff --git a/lib/tests_coordination.sh b/lib/tests_coordination.sh index 2b7eb07..07e1512 100644 --- a/lib/tests_coordination.sh +++ b/lib/tests_coordination.sh @@ -347,7 +347,7 @@ TEST_LAUNCHER () { # End the timer for the test stop_timer 2 - LXC_STOP $LXC_NAME + ynh_lxc_stop $LXC_NAME # Update the lock file with the date of the last finished test. # $$ is the PID of package_check itself. diff --git a/lib/ynh_lxd b/lib/ynh_lxd index 94e71dc..7c8691e 100644 --- a/lib/ynh_lxd +++ b/lib/ynh_lxd @@ -4,6 +4,19 @@ # LXD HELPERS #================================================= +ynh_lxc_stop () { + local container_to_stop=$1 + # (We also use timeout 30 in front of the command because sometime lxc + # commands can hang forever despite the --timeout >_>...) + timeout 30 lxc stop --timeout 15 $container_to_stop 2>/dev/null + + # If the command times out, then add the option --force + if [ $? -eq 124 ]; then + timeout 30 lxc stop --timeout 15 $container_to_stop --force 2>/dev/null + fi + +} + ynh_lxc_snapshot_exists () { local snapname=$1 lxc list --format json \ @@ -19,7 +32,7 @@ ynh_lxc_snapshot_load () { # Remove swap files before restoring the snapshot. CLEAN_SWAPFILES - LXC_STOP $LXC_NAME + ynh_lxc_stop $LXC_NAME lxc restore $LXC_NAME $snapname lxc start $LXC_NAME diff --git a/lib/ynh_lxd_package_check b/lib/ynh_lxd_package_check index 6c2d0ff..10001dc 100644 --- a/lib/ynh_lxd_package_check +++ b/lib/ynh_lxd_package_check @@ -161,7 +161,7 @@ ynh_lxc_pc_snapshot_create () { # Remove swap files to avoid killing the CI with huge snapshots. CLEAN_SWAPFILES - LXC_STOP $LXC_NAME + ynh_lxc_stop $LXC_NAME # Check if the snapshot already exist if ! ynh_lxc_snapshot_exists "$snapname" @@ -175,19 +175,6 @@ ynh_lxc_pc_snapshot_create () { stop_timer 1 } -LXC_STOP () { - local container_to_stop=$1 - # (We also use timeout 30 in front of the command because sometime lxc - # commands can hang forever despite the --timeout >_>...) - timeout 30 lxc stop --timeout 15 $container_to_stop 2>/dev/null - - # If the command times out, then add the option --force - if [ $? -eq 124 ]; then - timeout 30 lxc stop --timeout 15 $container_to_stop --force 2>/dev/null - fi - -} - LXC_RESET () { # If the container exists if lxc info $LXC_NAME >/dev/null 2>/dev/null; then @@ -195,7 +182,7 @@ LXC_RESET () { CLEAN_SWAPFILES fi - LXC_STOP $LXC_NAME + ynh_lxc_stop $LXC_NAME if lxc info $LXC_NAME >/dev/null 2>/dev/null; then local current_storage=$(lxc list $LXC_NAME --format json --columns b | jq '.[].expanded_devices.root.pool') @@ -210,7 +197,7 @@ _LXC_START_AND_WAIT() { restart_container() { - LXC_STOP $1 + ynh_lxc_stop $1 lxc start "$1" }