Files
buryan-infra/ops/sso/2026-10-19/fix-headscale-final.sh
T
architect c985c0617b
lint / hygiene (push) Failing after 30s
lint / hygiene (pull_request) Failing after 21s
standard / check (push) Successful in 9s
standard / check (pull_request) Successful in 14s
[INFRA] migrate active old VPS 193.233.210.184 to 45.133.209.253
2026-12-02 18:00:21 +03:00

62 lines
2.7 KiB
Bash

#!/bin/bash
# ============================================================
# headscale: домен должен вести на сам headscale, а не на вход
# ============================================================
# headscale на VPS слушает 0.0.0.0:8443 (TLS снимает nginx).
# Домашний headscale (CT 201) остановлен — узлов нет.
# Доступ: VPS → 127.0.0.1:8443, дом → 100.64.0.2:8443 (через сеть).
# Вход Authentik headscale не нужен: у него свои ключи узлов.
# ============================================================
set -uo pipefail
echo "=== 1. HEADSCALE ОТВЕЧАЕТ НА VPS? ==="
ssh -o BatchMode=yes [email protected] "curl -s -o /dev/null -w ' 127.0.0.1:8443/health -> %{http_code}\n' --max-time 6 http://127.0.0.1:8443/health; curl -s -o /dev/null -w ' 127.0.0.1:8443/windows -> %{http_code}\n' --max-time 6 http://127.0.0.1:8443/windows"
echo
echo "=== 2. VPS: направляю домен на headscale ==="
ssh -o BatchMode=yes [email protected] 'python3 - <<PY
import re
p = "/etc/nginx/conf.d/buryans-all.conf"
t = open(p, encoding="utf-8").read()
m = re.search(r"server_name\s+headscale\.buryans\.ru\s*;", t)
if not m:
print(" ❌ блок не найден")
else:
end = t.find("\n}", m.end())
block = t[m.end():end]
new = re.sub(r"proxy_pass\s+http://[^;]+;", "proxy_pass http://127.0.0.1:8443;", block)
t = t[:m.end()] + new + t[end:]
open(p, "w", encoding="utf-8").write(t)
print(" VPS: proxy_pass -> http://127.0.0.1:8443")
PY
nginx -t 2>&1 | tail -1; systemctl reload nginx && echo " VPS nginx перезагружен"' 2>&1 | sed 's/^/ /'
echo
echo "=== 3. ДОМА: направляю на VPS через сеть ==="
python3 - <<'PY'
import re
p = "/etc/nginx/conf.d/buryans-all.conf"
t = open(p, encoding="utf-8").read()
m = re.search(r"server_name\s+headscale\.buryans\.ru\s*;", t)
if not m:
print(" ❌ блок не найден")
else:
end = t.find("\n}", m.end())
block = t[m.end():end]
new = re.sub(r"proxy_pass\s+http://[^;]+;", "proxy_pass http://100.64.0.2:8443;", block)
t = t[:m.end()] + new + t[end:]
open(p, "w", encoding="utf-8").write(t)
print(" дом: proxy_pass -> http://100.64.0.2:8443")
PY
nginx -t 2>&1 | tail -1 | sed 's/^/ /'
systemctl reload nginx && echo " домашний nginx перезагружен"
echo
echo "=== 4. ПРОВЕРКА ==="
sleep 2
for p in /health /windows /; do
echo " $p -> $(curl -s -o /dev/null -w '%{http_code}' --max-time 12 -k https://headscale.buryans.ru$p)"
done
echo -n " страница: "
curl -s --max-time 12 -k https://headscale.buryans.ru/windows | grep -oiE '<title>[^<]*' | head -1