Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1085fd23c | ||
|
|
7406096b79 |
No files matched your search
+2
-1
@@ -56,13 +56,14 @@ fi
|
||||
|
||||
# --- files ------------------------------------------------------------------
|
||||
install -d -m 0755 /etc/wirecon /etc/wireguard /etc/conf.d \
|
||||
/etc/init.d /usr/local/bin /var/log
|
||||
/etc/init.d /usr/local/bin /var/log /var/lib/wirecon
|
||||
|
||||
log "deploying scripts"
|
||||
install -m 0755 "$SRC/usr/local/bin/wirecon-watchdog.sh" /usr/local/bin/
|
||||
install -m 0755 "$SRC/usr/local/bin/wirecon-watchdog-loop.sh" /usr/local/bin/
|
||||
install -m 0755 "$SRC/usr/local/bin/wirecon-monitor.sh" /usr/local/bin/
|
||||
install -m 0755 "$SRC/usr/local/bin/wirecon-mtu-probe.sh" /usr/local/bin/
|
||||
install -m 0755 "$SRC/usr/local/bin/wirecon-mtu-apply.sh" /usr/local/bin/
|
||||
|
||||
log "deploying OpenRC init scripts"
|
||||
install -m 0755 "$SRC/etc/init.d/wirecon-watchdog" /etc/init.d/
|
||||
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
# wirecon-mtu-apply.sh — one-shot: run wirecon-mtu-probe.sh against the current
|
||||
# WG peer endpoint, rewrite `MTU =` in /etc/wireguard/wg0.conf if the probe
|
||||
# recommends something different, restart wg-quick, drop a marker so future
|
||||
# watchdog ticks skip us.
|
||||
#
|
||||
# Invoked detached from wirecon-watchdog.sh on the first tick where a handshake
|
||||
# has happened and /var/lib/wirecon/mtu-probed.flag is absent. Marker stays
|
||||
# absent on probe failure so the next handshake retries.
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
WG_CONF="${WG_CONF:-/etc/wireguard/wg0.conf}"
|
||||
IFACE="${WG_INTERFACE:-wg0}"
|
||||
MARKER="${WIRECON_MTU_MARKER:-/var/lib/wirecon/mtu-probed.flag}"
|
||||
PROBE="${WIRECON_MTU_PROBE:-/usr/local/bin/wirecon-mtu-probe.sh}"
|
||||
|
||||
log() {
|
||||
local level="$1"; shift
|
||||
printf 'level=%s ts=%s %s\n' "$level" "$(date -u +%FT%TZ)" "$*"
|
||||
}
|
||||
|
||||
mkdir -p "$(dirname "$MARKER")"
|
||||
|
||||
if [[ -e "$MARKER" ]]; then
|
||||
log info "event=mtu_skip reason=marker_present"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
endpoint=$(awk -F'= *' '/^Endpoint/ {gsub(/:[0-9]+$/,"",$2); print $2; exit}' "$WG_CONF" 2>/dev/null || true)
|
||||
if [[ -z "$endpoint" || "$endpoint" == REPLACE_WITH_* ]]; then
|
||||
log warn "event=mtu_skip reason=no_real_endpoint endpoint=\"${endpoint:-<none>}\""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
current_mtu=$(awk -F'= *' '/^MTU/ {print $2; exit}' "$WG_CONF" 2>/dev/null | tr -d '[:space:]' || true)
|
||||
log info "event=mtu_probe_start endpoint=$endpoint current_mtu=${current_mtu:-?}"
|
||||
|
||||
probe_out=$("$PROBE" "$endpoint" 2>/dev/null || true)
|
||||
new_mtu=$(printf '%s\n' "$probe_out" | awk -F': *' '/^recommended WG MTU/ {print $2; exit}' | tr -d '[:space:]')
|
||||
|
||||
if [[ -z "$new_mtu" ]]; then
|
||||
log error "event=mtu_probe_failed endpoint=$endpoint"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$new_mtu" == "$current_mtu" ]]; then
|
||||
log info "event=mtu_noop mtu=$new_mtu"
|
||||
: > "$MARKER"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log info "event=mtu_apply old=${current_mtu:-?} new=$new_mtu"
|
||||
sed -i "s/^MTU = .*/MTU = ${new_mtu}/" "$WG_CONF"
|
||||
|
||||
if rc-service "wg-quick.$IFACE" restart >/dev/null 2>&1; then
|
||||
log info "event=mtu_applied old=${current_mtu:-?} new=$new_mtu"
|
||||
: > "$MARKER"
|
||||
else
|
||||
log error "event=mtu_restart_failed new=$new_mtu"
|
||||
exit 1
|
||||
fi
|
||||
@@ -85,6 +85,13 @@ age=$(handshake_age)
|
||||
lost=$(in_tunnel_ping)
|
||||
streak=$(read_streak)
|
||||
|
||||
# One-shot MTU probe on the first-ever successful handshake. The apply
|
||||
# helper short-circuits on its own marker; we only skip the fork here to
|
||||
# avoid spawning a subshell every tick once the marker exists.
|
||||
if [[ "$age" -ge 0 && ! -e /var/lib/wirecon/mtu-probed.flag ]]; then
|
||||
( /usr/local/bin/wirecon-mtu-apply.sh >>/var/log/wirecon-mtu.log 2>&1 ) &
|
||||
fi
|
||||
|
||||
reason=""
|
||||
if [[ "$age" -lt 0 ]]; then
|
||||
reason="no handshake ever"
|
||||
|
||||
@@ -167,11 +167,12 @@ exec /bin/login -f root
|
||||
AUTOLOGIN
|
||||
|
||||
pct exec "$VMID" -- sh -c '
|
||||
# Drop ANY existing getty line for tty1 (Alpine LXC inittab uses an empty
|
||||
# id field: "::respawn:/sbin/getty 38400 tty1"), then add the auto-login
|
||||
# variant with an explicit id so our line wins on any future re-run.
|
||||
# Alpine LXC inittab uses an empty id field: "::respawn:/sbin/getty 38400 tty1".
|
||||
# A non-empty id makes busybox init try to open /dev/<id> as the controlling
|
||||
# tty before exec — which fails on cold lxc-start and respawn-throttles the
|
||||
# line into silent-disabled. Keep the empty-id form so we survive reboots.
|
||||
sed -i -E "/getty.*tty1$/d" /etc/inittab
|
||||
echo "tty1::respawn:/sbin/getty -n -l /usr/local/sbin/autologin-root 38400 tty1" >> /etc/inittab
|
||||
echo "::respawn:/sbin/getty -n -l /usr/local/sbin/autologin-root 38400 tty1" >> /etc/inittab
|
||||
# Reload init and kick any running getty so it respawns from the new config.
|
||||
kill -HUP 1 2>/dev/null || true
|
||||
pkill -KILL getty 2>/dev/null || true
|
||||
|
||||
Reference in new issue
Block a user