From 6a853841111e52d18cfdf214f52bc0a82e69b826 Mon Sep 17 00:00:00 2001 From: Dushnilin Date: Wed, 26 Aug 2026 19:03:16 +0300 Subject: [PATCH] =?UTF-8?q?fix(tailscale):=20=D0=B3=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B4=D0=B5=D0=BC=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0,=20=D1=84=D0=BB=D0=B0=D0=B3=D0=B8=20tailscaled=20?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B5=D0=B9=D1=82=D1=80=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20standalone-=D1=81=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=B8=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - удалён неподдерживаемый флаг --netfilter-mode=on, вызывавший ошибку старта на OpenWrt - проба готовности парсит status --json (BackendState), а не exit-code: незалогиненный узел отвечает NeedsLogin с non-zero и раньше считался неготовым — корень «did not become ready» при первом входе - перед стартом своего tailscaled останавливается и отключается init-скрипт официального пакета: его демон держал UDP 41641, из-за чего наш умирал мгновенно - при сбое старта в лог пишется хвост tailscaled.log для диагностики --- .../usr/lib/providers/tailscale/runtime.uc | 53 +++++++++++++++++-- tests/tailscale_native_runtime.sh | 12 +++++ 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/tachyon/files/usr/lib/providers/tailscale/runtime.uc b/tachyon/files/usr/lib/providers/tailscale/runtime.uc index 8d938c15..5210a9ea 100644 --- a/tachyon/files/usr/lib/providers/tailscale/runtime.uc +++ b/tachyon/files/usr/lib/providers/tailscale/runtime.uc @@ -310,12 +310,46 @@ function install_kernel_routing(section) { return true; } +// The official package ships its own init script; if it autostarted at boot, +// its daemon holds UDP 41641 and ours dies instantly. Neutralize it the same +// way component install does - stop + disable, idempotent. +function file_executable(path) { + let st = fs.stat(path); + return st != null && st.mode != null && (int(st.mode) & 73) != 0; +} + +function neutralize_standalone_service() { + let init = "/etc/init.d/tailscale"; + if (!file_executable(init)) + return; + command_status(command_from_args([ init, "stop" ]) + " >/dev/null 2>&1"); + command_status(command_from_args([ init, "disable" ]) + " >/dev/null 2>&1"); + log_message("standalone tailscale service stopped and disabled", "info"); +} + +function log_file_tail(path) { + let data = ""; + try { + data = as_string(fs.readfile(path)) || ""; + } catch (e) { + return ""; + } + let lines = split(trim(data), "\n"); + let start = length(lines) > 5 ? length(lines) - 5 : 0; + let tail = []; + for (let i = start; i < length(lines); i++) + push(tail, lines[i]); + return join(" | ", tail); +} + function start_daemon(section) { if (running_pid(section)) { log_message("tailscaled for " + section_name(section) + " already running", "debug"); return true; } + neutralize_standalone_service(); + let runtime_dir = section_runtime_dir(section); let socket_path = runtime_dir + "/tailscaled.sock"; let log_file = runtime_dir + "/tailscaled.log"; @@ -326,10 +360,10 @@ function start_daemon(section) { "--tun=tailscale0", "--statedir=" + state_dir, "--socket=" + socket_path, - "--port=" + TAILSCALED_PORT, - "--netfilter-mode=on" + "--port=" + TAILSCALED_PORT ]; + fs.unlink(log_file); let cmdline = command_from_args(args) + " >" + shell_quote(log_file) + " 2>&1 = 0) return true; if (!pid_alive(pid)) break; command_success_from_args([ "sleep", "1" ]); } - log_message("tailscaled did not become ready for " + section_name(section), "warn"); + + let tail = log_file_tail(log_file); + if (!pid_alive(pid)) + log_message("tailscaled for " + section_name(section) + " exited during startup; log tail: " + (tail == "" ? "" : tail), "warn"); + else + log_message("tailscaled did not become ready for " + section_name(section) + "; log tail: " + (tail == "" ? "" : tail), "warn"); return false; } diff --git a/tests/tailscale_native_runtime.sh b/tests/tailscale_native_runtime.sh index 92c425a3..c6896ef9 100644 --- a/tests/tailscale_native_runtime.sh +++ b/tests/tailscale_native_runtime.sh @@ -89,7 +89,19 @@ run() { run installed || fail "installed must succeed with stubs present" # --- start ------------------------------------------------------------------ +# Fake official init script: must be stopped+disabled before our daemon starts. +INIT_LOG="$WORK_DIR/init.log" +mkdir -p /etc/init.d +cat >"/etc/init.d/tailscale" <> '$INIT_LOG' +exit 0 +EOF +chmod +x "/etc/init.d/tailscale" + run start-runtime || fail "start-runtime exited non-zero" +grep -Fq "stop" "$INIT_LOG" || fail "standalone tailscale service was not stopped" +grep -Fq "disable" "$INIT_LOG" || fail "standalone tailscale service was not disabled" PID_FILE="$WORK_DIR/run/ts_native/tailscaled.pid" [ -f "$PID_FILE" ] || fail "pid file was not written"