mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
Fix retry mechanism ... add another retry mechanism for LXC_STOP ...
This commit is contained in:
parent
252a3abea4
commit
5db177ccc8
1 changed files with 19 additions and 12 deletions
29
lib/lxc.sh
29
lib/lxc.sh
|
@ -86,15 +86,13 @@ LOAD_LXC_SNAPSHOT () {
|
||||||
while [[ ${retry_lxc} -lt 10 ]]
|
while [[ ${retry_lxc} -lt 10 ]]
|
||||||
do
|
do
|
||||||
LXC_STOP $LXC_NAME || true
|
LXC_STOP $LXC_NAME || true
|
||||||
lxc restore $LXC_NAME $snapname && break || retry_lxc+=1
|
lxc restore $LXC_NAME $snapname && break || retry_lxc=$(($retry_lxc+1))
|
||||||
log_info "$retry_lxc"
|
log_warning "Failed to restore snapshot? Retrying in 20 sec ..."
|
||||||
log_warning "Failed to stop LXC and restore snapshot? Retrying in 20 sec ..."
|
|
||||||
sleep 20
|
sleep 20
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${retry_lxc} -ge 10 ]]
|
if [[ ${retry_lxc} -ge 10 ]]
|
||||||
then
|
then
|
||||||
log_info "$retry_lxc"
|
|
||||||
log_error "Failed to restore snapshot ? The next step may miserably crash because of this ... if this happens to often, maybe restarting the LXD daemon can help ..."
|
log_error "Failed to restore snapshot ? The next step may miserably crash because of this ... if this happens to often, maybe restarting the LXD daemon can help ..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -130,16 +128,25 @@ LXC_STOP () {
|
||||||
# (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 $container_to_stop 2>/dev/null
|
timeout 30 lxc stop --timeout 15 $container_to_stop 2>/dev/null
|
||||||
local ret=$?
|
|
||||||
|
|
||||||
# If the command times out, then add the option --force
|
local retry_stop_lxc=0
|
||||||
if [ $ret -eq 124 ]; then
|
while && [[ ${retry_stop_lxc} -lt 5 ]]
|
||||||
timeout 30 lxc stop --timeout 15 $container_to_stop --force 2>/dev/null
|
do
|
||||||
elif [ $ret -ne 0 ]; then
|
local status="$(lxc list $container_to_stop --format json | jq -r '.[].state.status')"
|
||||||
log_warning "Tried to stop lxc, got ret $ret"
|
if [[ -z "$status" ]] || [[ "$status" == "Stopped" ]]
|
||||||
log_warning $(lxc list $container_to_stop --format json | jq -r '.[].state.status')
|
then
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
|
log_warning "Failed to stop LXC (status=$status) ? Retrying in 10 sec ..."
|
||||||
|
retry_stop_lxc="$(($retry_stop_lxc+1))"
|
||||||
|
sleep 10
|
||||||
|
timeout 30 lxc stop --timeout 15 $container_to_stop 2>/dev/null
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${retry_stop_lxc} -ge 5 ]]
|
||||||
|
then
|
||||||
|
timeout 30 lxc stop --timeout 15 $container_to_stop --force 2>/dev/null
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
LXC_RESET () {
|
LXC_RESET () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue