From c813e450cd458221fa6a99f36b40a98299b0cbcb Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 30 Apr 2020 19:30:39 +0200 Subject: [PATCH] restart if no internet access --- utils.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/utils.sh b/utils.sh index 32f9ed2..d55041e 100755 --- a/utils.sh +++ b/utils.sh @@ -42,6 +42,23 @@ wait_container() sleep 1s done + + # Wait for container to access the internet + for i in $(seq 1 10); do + if lxc exec "$1" -- /bin/bash -c "ping -q -c 2 security.debian.org" >/dev/null 2>/dev/null; then + break + fi + + if [ "$i" == "10" ]; then + echo 'Waited for 10 seconds to access the internet, restarting..' + lxc stop "$1" + lxc start "$1" + + wait_container "$1" + fi + + sleep 1s + done } rotate_image()