use LXC_STOP where we need to stop a container

This commit is contained in:
Kay0u 2021-12-12 20:20:24 +01:00
parent ff0dcc2207
commit e949d99c16
No known key found for this signature in database
GPG key ID: AE1DCADB6415A156
2 changed files with 15 additions and 6 deletions

View file

@ -58,7 +58,7 @@ CREATE_LXC_SNAPSHOT () {
# Remove swap files to avoid killing the CI with huge snapshots. # Remove swap files to avoid killing the CI with huge snapshots.
CLEAN_SWAPFILES CLEAN_SWAPFILES
timeout 30 lxc stop --timeout 15 $LXC_NAME 2>/dev/null LXC_STOP $LXC_NAME
# Check if the snapshot already exist # Check if the snapshot already exist
if ! LXC_SNAPSHOT_EXISTS "$snapname" if ! LXC_SNAPSHOT_EXISTS "$snapname"
@ -79,7 +79,8 @@ LOAD_LXC_SNAPSHOT () {
# Remove swap files before restoring the snapshot. # Remove swap files before restoring the snapshot.
CLEAN_SWAPFILES CLEAN_SWAPFILES
timeout 30 lxc stop --timeout 15 $LXC_NAME 2>/dev/null LXC_STOP $LXC_NAME
lxc restore $LXC_NAME $snapname lxc restore $LXC_NAME $snapname
lxc start $LXC_NAME lxc start $LXC_NAME
_LXC_START_AND_WAIT $LXC_NAME _LXC_START_AND_WAIT $LXC_NAME
@ -109,9 +110,16 @@ LXC_EXEC () {
} }
LXC_STOP () { LXC_STOP () {
local container_to_stop=$1
# (We also use timeout 30 in front of the command because sometime lxc # (We also use timeout 30 in front of the command because sometime lxc
# commands can hang forever despite the --timeout >_>...) # commands can hang forever despite the --timeout >_>...)
timeout 30 lxc stop --timeout 15 $LXC_NAME 2>/dev/null 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 () { LXC_RESET () {
@ -121,7 +129,8 @@ LXC_RESET () {
CLEAN_SWAPFILES CLEAN_SWAPFILES
fi fi
timeout 30 lxc stop --timeout 15 $LXC_NAME --force 2>/dev/null LXC_STOP $LXC_NAME
lxc delete $LXC_NAME --force 2>/dev/null lxc delete $LXC_NAME --force 2>/dev/null
} }
@ -130,7 +139,7 @@ _LXC_START_AND_WAIT() {
restart_container() restart_container()
{ {
timeout 30 lxc stop --timeout 15 $1 2>/dev/null LXC_STOP $1
lxc start "$1" lxc start "$1"
} }

View file

@ -366,7 +366,7 @@ TEST_LAUNCHER () {
# End the timer for the test # End the timer for the test
stop_timer 2 stop_timer 2
LXC_STOP LXC_STOP $LXC_NAME
# Update the lock file with the date of the last finished test. # Update the lock file with the date of the last finished test.
# $$ is the PID of package_check itself. # $$ is the PID of package_check itself.