fix(tunnel): close stdin so autossh survives backgrounding; add quick "+ Тоннель" button

Background autossh died immediately because nohup left stdin attached to the
closed curl pipe — autossh saw EOF and bailed. Add </dev/null and wrap in
subshell so the process is fully detached from the install script's session.

Also add an "+ Тоннель" button next to "+ Добавить": creates a router with a
placeholder base URL and opens the tunnel modal in one click — for routers
without a public IP that have nothing to put in the base URL field yet.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Андрей Бобырев
2026-04-27 22:30:43 +03:00
parent 61d80ebc22
commit 3f2d621d02
2 changed files with 40 additions and 6 deletions

View File

@@ -414,9 +414,9 @@ chmod +x /opt/bin/kdns_tun
cat > /opt/etc/init.d/S99kdns_tun <<'INITEOF'
#!/bin/sh
case "$1" in
start) killall -0 autossh 2>/dev/null || nohup /opt/bin/kdns_tun >/dev/null 2>&1 & ;;
start) killall -0 autossh 2>/dev/null || ( nohup /opt/bin/kdns_tun </dev/null >/dev/null 2>&1 & ) ;;
stop) killall autossh 2>/dev/null ;;
restart) killall autossh 2>/dev/null; sleep 1; nohup /opt/bin/kdns_tun >/dev/null 2>&1 & ;;
restart) killall autossh 2>/dev/null; sleep 1; ( nohup /opt/bin/kdns_tun </dev/null >/dev/null 2>&1 & ) ;;
esac
INITEOF
chmod +x /opt/etc/init.d/S99kdns_tun
@@ -424,8 +424,10 @@ chmod +x /opt/etc/init.d/S99kdns_tun
echo '[4/4] Запуск...'
killall autossh 2>/dev/null || true
sleep 1
nohup /opt/bin/kdns_tun >/dev/null 2>&1 &
sleep 3
# stdin=/dev/null обязательно: иначе autossh ловит EOF от закрытой curl-трубы и сразу выходит.
# subshell ( ... ) полностью отрывает процесс от родительского sh.
( nohup /opt/bin/kdns_tun </dev/null >/dev/null 2>&1 & )
sleep 4
if killall -0 autossh 2>/dev/null; then
echo
echo '=== OK ==='
@@ -433,8 +435,9 @@ if killall -0 autossh 2>/dev/null; then
echo 'Возвращайся в браузер и жми "Проверить связь"'
else
echo
echo '=== ОШИБКА: autossh не запустился ==='
echo 'Тест вручную: /opt/bin/kdns_tun (Ctrl+C для выхода)'
echo '=== ОШИБКА: autossh не запустился в фоне ==='
echo 'Тест вручную (должно работать): /opt/bin/kdns_tun (Ctrl+C для выхода)'
echo 'Если вручную работает — попробуй: ( nohup /opt/bin/kdns_tun </dev/null >/dev/null 2>&1 & )'
exit 1
fi
"""