Compare commits

...

4 commits

Author SHA1 Message Date
Geir Okkenhaug Jerstad
4cb3852039 expanded lab script maybe we need to switvh to smoething other than bash soon 2025-06-12 21:42:00 +02:00
Geir Okkenhaug Jerstad
9274ab1e17 Improve SSH diagnostics in lab status command 2025-06-12 21:26:59 +02:00
Geir Okkenhaug Jerstad
38bc909c6a Fix SSH user in lab status command 2025-06-12 21:25:37 +02:00
Geir Okkenhaug Jerstad
53480c72bc Improve lab status command to check both LAN and Tailscale connectivity 2025-06-12 21:21:59 +02:00

View file

@ -1,5 +1,11 @@
{ lib, stdenv, writeShellScriptBin, rsync, openssh, ... }:
{
lib,
stdenv,
writeShellScriptBin,
rsync,
openssh,
...
}:
writeShellScriptBin "lab" ''
#!/usr/bin/env bash
@ -62,7 +68,7 @@ writeShellScriptBin "lab" ''
local target_host="sma@grey-area"
;;
"reverse-proxy")
local target_host="sma@reverse-proxy"
local target_host="sma@reverse-proxy.tail807ea.ts.net"
;;
*)
error "Unknown machine: $machine"
@ -128,12 +134,55 @@ writeShellScriptBin "lab" ''
warn " congenital-optimist: Tailscale inactive"
fi
# Check if -v (verbose) flag is passed
local verbose=0
if [[ "''${1:-}" == "-v" ]]; then
verbose=1
fi
# Check remote machines
for machine in sleeper-service grey-area reverse-proxy; do
if ${openssh}/bin/ssh -o ConnectTimeout=5 -o BatchMode=yes "sma@$machine" "echo OK" >/dev/null 2>&1; then
success " $machine: Online"
local ssh_user="sma" # Using sma as the admin user for remote machines
# Test SSH connectivity with debug info if in verbose mode
if [[ $verbose -eq 1 ]]; then
log "Testing SSH connection to $machine (LAN)..."
${openssh}/bin/ssh -v -o ConnectTimeout=5 -o BatchMode=yes "$ssh_user@$machine" "echo SSH connection to $machine successful" 2>&1
# Use specific hostname for reverse-proxy
if [[ "$machine" == "reverse-proxy" ]]; then
log "Testing SSH connection to reverse-proxy.tail807ea.ts.net (Tailscale)..."
${openssh}/bin/ssh -v -o ConnectTimeout=5 -o BatchMode=yes "$ssh_user@reverse-proxy.tail807ea.ts.net" "echo SSH connection to reverse-proxy.tail807ea.ts.net successful" 2>&1
else
log "Testing SSH connection to $machine.tailnet (Tailscale)..."
${openssh}/bin/ssh -v -o ConnectTimeout=5 -o BatchMode=yes "$ssh_user@$machine.tailnet" "echo SSH connection to $machine.tailnet successful" 2>&1
fi
fi
# For reverse-proxy, try Tailscale first as it's likely only accessible that way
if [[ "$machine" == "reverse-proxy" ]]; then
# Use the specific Tailscale hostname for reverse-proxy
if ${openssh}/bin/ssh -o ConnectTimeout=5 -o BatchMode=yes "$ssh_user@reverse-proxy.tail807ea.ts.net" "echo OK" >/dev/null 2>&1; then
success " $machine: Online (Tailscale)"
elif ${openssh}/bin/ssh -o ConnectTimeout=2 -o BatchMode=yes "$ssh_user@$machine" "echo OK" >/dev/null 2>&1; then
success " $machine: Online (LAN)"
else
warn " $machine: Unreachable"
if [[ $verbose -eq 1 ]]; then
log " Note: reverse-proxy is likely only accessible via Tailscale"
log " Check if Tailscale is running on both machines and if the SSH service is active"
fi
fi
# For other machines, try LAN first then Tailscale as fallback
else
warn " $machine: Unreachable"
if ${openssh}/bin/ssh -o ConnectTimeout=2 -o BatchMode=yes "$ssh_user@$machine" "echo OK" >/dev/null 2>&1; then
success " $machine: Online (LAN)"
# Try with Tailscale hostname as fallback
elif ${openssh}/bin/ssh -o ConnectTimeout=3 -o BatchMode=yes "$ssh_user@$machine.tailnet" "echo OK" >/dev/null 2>&1; then
success " $machine: Online (Tailscale)"
else
warn " $machine: Unreachable"
fi
fi
done
}