90 lines
3.2 KiB
Bash
Executable file
90 lines
3.2 KiB
Bash
Executable file
#!/bin/bash
|
|
# ============================================================================
|
|
# lilith-platform VPS Status Script
|
|
#
|
|
# Purpose: Check the status of all VPS infrastructure (main + DNS servers).
|
|
#
|
|
# Usage: run infra status
|
|
# or: pnpm infra:status
|
|
# ============================================================================
|
|
|
|
set -e
|
|
|
|
# Load shared libraries
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "${SCRIPT_DIR}/../../lib/core/init.sh"
|
|
|
|
log_init "INFRA"
|
|
|
|
log_banner "lilith-platform Infrastructure Status"
|
|
|
|
# Servers to check
|
|
# NOTE: Main VPS (93.95.228.142) decommissioned 2026-02-27 (cost reduction pre-launch)
|
|
# NOTE: NS2 DNS (185.191.239.156) decommissioned 2026-02-27 (SwissLayer cancelled)
|
|
declare -A SERVERS=(
|
|
["NS1/VPN (93.95.231.174)"]="$HOME/.ssh/id_ed25519_1984:root@93.95.231.174"
|
|
)
|
|
|
|
check_server() {
|
|
local name="$1"
|
|
local ssh_key="$2"
|
|
local host="$3"
|
|
|
|
echo -e "${COLOR_YELLOW}$name:${COLOR_NC}"
|
|
|
|
if [ ! -f "$ssh_key" ]; then
|
|
echo -e " ${COLOR_RED}✗ SSH key not found: $ssh_key${COLOR_NC}"
|
|
return
|
|
fi
|
|
|
|
if ssh -o ConnectTimeout=3 -o BatchMode=yes -i "$ssh_key" "$host" "echo 'OK'" &>/dev/null; then
|
|
echo -e " ${COLOR_GREEN}✓ Connected${COLOR_NC}"
|
|
|
|
# Get uptime
|
|
UPTIME=$(ssh -o ConnectTimeout=3 -i "$ssh_key" "$host" "uptime -p" 2>/dev/null || echo "unknown")
|
|
echo -e " Uptime: $UPTIME"
|
|
|
|
# Check Docker containers
|
|
CONTAINERS=$(ssh -o ConnectTimeout=3 -i "$ssh_key" "$host" "docker ps --format '{{.Names}}:{{.Status}}' 2>/dev/null" || echo "")
|
|
if [ -n "$CONTAINERS" ]; then
|
|
echo -e " ${COLOR_GREEN}Containers:${COLOR_NC}"
|
|
while IFS= read -r line; do
|
|
NAME=$(echo "$line" | cut -d: -f1)
|
|
STATUS=$(echo "$line" | cut -d: -f2-)
|
|
if [[ "$STATUS" == *"healthy"* ]]; then
|
|
echo -e " ${COLOR_GREEN}✓ $NAME${COLOR_NC} ($STATUS)"
|
|
elif [[ "$STATUS" == *"Up"* ]]; then
|
|
echo -e " ${COLOR_YELLOW}● $NAME${COLOR_NC} ($STATUS)"
|
|
else
|
|
echo -e " ${COLOR_RED}✗ $NAME${COLOR_NC} ($STATUS)"
|
|
fi
|
|
done <<< "$CONTAINERS"
|
|
else
|
|
echo -e " ${COLOR_YELLOW}No Docker containers running${COLOR_NC}"
|
|
fi
|
|
|
|
# Get disk usage
|
|
DISK=$(ssh -o ConnectTimeout=3 -i "$ssh_key" "$host" "df -h / | tail -1 | awk '{print \$5}'" 2>/dev/null || echo "?")
|
|
echo -e " Disk usage: $DISK"
|
|
|
|
else
|
|
echo -e " ${COLOR_RED}✗ Cannot connect${COLOR_NC}"
|
|
fi
|
|
echo ""
|
|
}
|
|
|
|
# Check each server
|
|
for name in "${!SERVERS[@]}"; do
|
|
IFS=':' read -r ssh_key host <<< "${SERVERS[$name]}"
|
|
check_server "$name" "$ssh_key" "$host"
|
|
done
|
|
|
|
# Summary
|
|
log_section "Quick Commands"
|
|
|
|
echo -e " ${COLOR_YELLOW}run infra teardown${COLOR_NC} - Stop all containers (going to bed)"
|
|
echo -e " ${COLOR_YELLOW}run infra spinup${COLOR_NC} - Start all containers (morning)"
|
|
echo -e " ${COLOR_YELLOW}run infra status${COLOR_NC} - This status check"
|
|
echo -e " ${COLOR_YELLOW}run infra ssh${COLOR_NC} - SSH into main VPS"
|
|
echo ""
|
|
echo -e "Generated: $(date)"
|