From 41ed765b9aff75dd43c66f9008c05a0e6c344b86 Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Tue, 6 Dec 2022 20:13:10 -0800 Subject: [PATCH] Keep attempting to bring up the network After a total power outage (system and networking gear), it's possible that the system boots up and blow through all the timeouts for DHCP before the network is operational. Unfortunately, I can't always solve that. --- debian/changelog | 7 +++++++ scripts/init-bottom/tailscale | 3 +-- scripts/init-premount/tailscale | 28 ++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 795b8c8..8d0b204 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +tailscale-initramfs (0.2) unstable; urgency=medium + + * Keep trying to bring up the network until it either comes up or the boot + process continues. + + -- Paul Aurich Tue, 06 Dec 2022 20:12:18 -0800 + tailscale-initramfs (0.1) unstable; urgency=medium * Initial Release. diff --git a/scripts/init-bottom/tailscale b/scripts/init-bottom/tailscale index 3fb2ead..0cf70a0 100755 --- a/scripts/init-bottom/tailscale +++ b/scripts/init-bottom/tailscale @@ -33,6 +33,7 @@ wait_for_tailscaled() # SC3043: In POSIX sh, 'local' is undefined. local pid exe timer="$TAILSCALE_SHUTDOWN_TIMEOUT" pid="$(cat "$PIDFILE" 2>/dev/null)" || return 1 + rm -f "$PIDFILE" while [ $timer -gt 0 ] && exe="$(readlink -f "/proc/$pid/exe" 2>/dev/null)"; do if [ "$exe" = "$EXE" ]; then @@ -60,8 +61,6 @@ if PID="$(wait_for_tailscaled)"; then log_end_msg fi -rm -f "$PIDFILE" - if [ "$BOOT" != nfs ] && [ "$IFDOWN" != none ]; then for IFACE in /sys/class/net/$IFDOWN; do [ -e "$IFACE" ] || continue diff --git a/scripts/init-premount/tailscale b/scripts/init-premount/tailscale index d3f32cc..ed36d79 100755 --- a/scripts/init-premount/tailscale +++ b/scripts/init-premount/tailscale @@ -19,6 +19,8 @@ esac . /scripts/functions +PIDFILE="/run/tailscale.pid" + if [ -e /etc/tailscale/initramfs/config ]; then . /etc/tailscale/initramfs/config fi @@ -33,6 +35,16 @@ if [ -z "${TAILSCALE_HOSTNAME-}" ]; then TAILSCALE_HOSTNAME=${HOSTNAME}-initramfs fi +network_up() +{ + for conf in /run/net-*.conf /run/net6-*.conf; do + if [ -e "$conf" ]; then + return 0 + fi + done + return 1 +} + # shellcheck disable=SC2039,SC2086,SC3043 run_tailscale() { @@ -42,7 +54,19 @@ run_tailscale() # FIXME: This races with dropbear-initramfs bringing up the network # asynchronously - [ "$BOOT" = nfs ] || configure_networking + if [ "$BOOT" != nfs ]; then + # Keep trying to bring up the network until it's up + # or the boot process continues toward finish. + while true; do + # "." builtin (in dash) exits on error. Run configure_networking + # in a subshell and wait for it. + configure_networking & + wait $! + if ! [ -e "$PIDFILE" ] || network_up; then + break + fi + done + fi # A little race-y to start the client before the daemon, but the client # will attempt to connect to the socket for a while. @@ -59,6 +83,6 @@ run_tailscale() modprobe tun run_tailscale & -echo $! > /run/tailscale.pid +echo $! > "$PIDFILE" exit 0