Improving _ynh_lxc_start_and_wait

This commit is contained in:
yalh76 2022-10-24 01:55:07 +02:00
parent f5332971ed
commit ffa77e8e61

View file

@ -211,6 +211,7 @@ _ynh_lxc_start_and_wait () {
ynh_handle_getopts_args "$@"
# Try to start the container 3 times.
ynh_lxc_start --name=$name
local max_try=3
local i=0
while [ $i -lt $max_try ]
@ -221,7 +222,8 @@ _ynh_lxc_start_and_wait () {
# Wait for container to start, we are using systemd to check this,
# for the sake of brevity.
for j in $(seq 1 10); do
if lxc exec "$name" -- systemctl isolate multi-user.target >/dev/null 2>/dev/null; then
if ynh_lxc_run_inside --name=$name --command="systemctl isolate multi-user.target >/dev/null 2>/dev/null"
then
break
fi
@ -237,7 +239,8 @@ _ynh_lxc_start_and_wait () {
# Wait for container to access the internet
for j in $(seq 1 10); do
if lxc exec "$name" -- curl -s http://wikipedia.org > /dev/null 2>/dev/null; then
if ynh_lxc_run_inside --name=$name --command="curl -s http://wikipedia.org > /dev/null 2>/dev/null"
then
break
fi
@ -266,7 +269,7 @@ _ynh_lxc_start_and_wait () {
fi
done
LXC_IP=$(lxc exec $name -- hostname -I | cut -d' ' -f1 | grep -E -o "\<[0-9.]{8,}\>")
LXC_IP=$(ynh_lxc_run_inside --name=$name --command="hostname -I | cut -d' ' -f1 | grep -E -o \"\<[0-9.]{8,}\>\"")
}
# Launch a new LXC from an image
@ -321,7 +324,6 @@ ynh_lxc_swapfiles_clean () {
# Restart it if needed
if [ "$(lxc info $name | grep Status | awk '{print tolower($2)}')" != "running" ]; then
ynh_lxc_start --name=$name
_ynh_lxc_start_and_wait --name=$name
fi
lxc exec $name -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do swapoff $swapfile; done'
@ -407,7 +409,6 @@ ynh_lxc_snapshot_load () {
ynh_lxc_stop --name=$name
lxc restore $name $snapname
ynh_lxc_start --name=$name
_ynh_lxc_start_and_wait --name=$name
}