From ceb657d237dbf391ba2b149dcc931f9d8b9a2cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Fri, 24 Jan 2020 10:27:54 +0100 Subject: [PATCH] Make sur resolvconf is populated before SSH key fetch --- bin/uncloud-init | 26 +++++++++++++++++++++++++- uncloud-init.rc | 2 +- uncloud-init.service | 1 - 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/bin/uncloud-init b/bin/uncloud-init index 612aac1..21c3988 100755 --- a/bin/uncloud-init +++ b/bin/uncloud-init @@ -107,13 +107,37 @@ up_network_interfaces () { done } +# XXX: fail after N iterations? +wait_for_resolvconf () { + # Check if RDNSSD daemon is running. + if ! pgrep rdnssd; then + echo "RDNSSD does not seems to be running!" >&2 + # XXX: start rdnssd? + fi + + echo "Waiting for resolv.conf to be populated..." + if [ ! -f '/etc/resolv.conf' ]; then + if [ "$(wc -l < resolv.conf)" = "0" ]; then + sleep 1 + wait_for_resolvconf + else + return + fi + else + touch '/etc/resolv.conf' + sleep 1 + wait_for_resolvconf + fi +} + ### # Entrypoint. if [ "$ENABLE_NETWORKING" = '1' ]; then - routine='up main network interface' + routine='setting up networking' echo "--- RUNNING $routine..." up_network_interfaces + wait_for_resolvconf echo "--- DONE with $routine." fi diff --git a/uncloud-init.rc b/uncloud-init.rc index a5d2ab5..7c9e8f1 100755 --- a/uncloud-init.rc +++ b/uncloud-init.rc @@ -6,7 +6,7 @@ name="$RC_SVCNAME" depend() { - use net logger rdnssd + use net logger before sshd } diff --git a/uncloud-init.service b/uncloud-init.service index aef6e7f..82493c4 100644 --- a/uncloud-init.service +++ b/uncloud-init.service @@ -1,6 +1,5 @@ [Unit] Description=Initialize an Uncloud virtual machine -After=rdnssd.service Before=network.target Requires=network.target