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.
This commit is contained in:
Paul Aurich
2022-12-06 20:13:10 -08:00
parent d28843e531
commit 41ed765b9a
3 changed files with 34 additions and 4 deletions

7
debian/changelog vendored
View File

@@ -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 <paul@darkrain42.org> Tue, 06 Dec 2022 20:12:18 -0800
tailscale-initramfs (0.1) unstable; urgency=medium tailscale-initramfs (0.1) unstable; urgency=medium
* Initial Release. * Initial Release.

View File

@@ -33,6 +33,7 @@ wait_for_tailscaled()
# SC3043: In POSIX sh, 'local' is undefined. # SC3043: In POSIX sh, 'local' is undefined.
local pid exe timer="$TAILSCALE_SHUTDOWN_TIMEOUT" local pid exe timer="$TAILSCALE_SHUTDOWN_TIMEOUT"
pid="$(cat "$PIDFILE" 2>/dev/null)" || return 1 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 while [ $timer -gt 0 ] && exe="$(readlink -f "/proc/$pid/exe" 2>/dev/null)"; do
if [ "$exe" = "$EXE" ]; then if [ "$exe" = "$EXE" ]; then
@@ -60,8 +61,6 @@ if PID="$(wait_for_tailscaled)"; then
log_end_msg log_end_msg
fi fi
rm -f "$PIDFILE"
if [ "$BOOT" != nfs ] && [ "$IFDOWN" != none ]; then if [ "$BOOT" != nfs ] && [ "$IFDOWN" != none ]; then
for IFACE in /sys/class/net/$IFDOWN; do for IFACE in /sys/class/net/$IFDOWN; do
[ -e "$IFACE" ] || continue [ -e "$IFACE" ] || continue

View File

@@ -19,6 +19,8 @@ esac
. /scripts/functions . /scripts/functions
PIDFILE="/run/tailscale.pid"
if [ -e /etc/tailscale/initramfs/config ]; then if [ -e /etc/tailscale/initramfs/config ]; then
. /etc/tailscale/initramfs/config . /etc/tailscale/initramfs/config
fi fi
@@ -33,6 +35,16 @@ if [ -z "${TAILSCALE_HOSTNAME-}" ]; then
TAILSCALE_HOSTNAME=${HOSTNAME}-initramfs TAILSCALE_HOSTNAME=${HOSTNAME}-initramfs
fi 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 # shellcheck disable=SC2039,SC2086,SC3043
run_tailscale() run_tailscale()
{ {
@@ -42,7 +54,19 @@ run_tailscale()
# FIXME: This races with dropbear-initramfs bringing up the network # FIXME: This races with dropbear-initramfs bringing up the network
# asynchronously # 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 # A little race-y to start the client before the daemon, but the client
# will attempt to connect to the socket for a while. # will attempt to connect to the socket for a while.
@@ -59,6 +83,6 @@ run_tailscale()
modprobe tun modprobe tun
run_tailscale & run_tailscale &
echo $! > /run/tailscale.pid echo $! > "$PIDFILE"
exit 0 exit 0