121 lines
4.1 KiB
Bash
Executable file
121 lines
4.1 KiB
Bash
Executable file
#!/bin/bash
|
|
# ============================================================================
|
|
# lilith-platform VPS Spinup Script
|
|
#
|
|
# Purpose: Start all Docker containers on the production VPS after teardown.
|
|
#
|
|
# Usage: run infra spinup
|
|
# or: pnpm infra:spinup
|
|
#
|
|
# Note: This starts containers in the correct order with health checks.
|
|
# ============================================================================
|
|
|
|
set -e
|
|
|
|
# Load shared libraries
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "${SCRIPT_DIR}/../../lib/core/init.sh"
|
|
|
|
log_init "INFRA"
|
|
|
|
# Configuration
|
|
VPS_HOST="${VPS_HOST:-93.95.228.142}"
|
|
VPS_USER="${VPS_USER:-root}"
|
|
SSH_KEY="${SSH_KEY:-$HOME/.ssh/id_ed25519_1984}"
|
|
COMPOSE_FILE="${COMPOSE_FILE:-/opt/lilith-platform/docker-compose.yml}"
|
|
|
|
log_banner "lilith-platform VPS Spinup"
|
|
|
|
# DECOMMISSIONED 2026-02-27: Platform VPS dropped pre-launch to save ~$50/mo
|
|
log_error "Platform VPS (93.95.228.142) is DECOMMISSIONED."
|
|
log_info "The big VPS was dropped pre-launch to reduce costs."
|
|
log_info "To re-provision: spin up new VPS, run tooling/scripts/vps/setup/, update DNS."
|
|
exit 1
|
|
|
|
# Check SSH key exists
|
|
if [ ! -f "$SSH_KEY" ]; then
|
|
log_error "SSH key not found at $SSH_KEY"
|
|
echo "Set SSH_KEY environment variable or create the key"
|
|
exit 1
|
|
fi
|
|
|
|
# Check SSH connectivity
|
|
log_step "Checking VPS connectivity..."
|
|
if ! ssh -o ConnectTimeout=5 -o BatchMode=yes -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "echo 'Connected'" &>/dev/null; then
|
|
log_error "Cannot connect to VPS at $VPS_HOST"
|
|
echo "Check your SSH key and network connection"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "Connected to VPS"
|
|
echo ""
|
|
|
|
# Show current state
|
|
log_step "Current running containers:"
|
|
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker ps --format 'table {{.Names}}\t{{.Status}}'" || true
|
|
echo ""
|
|
|
|
# Check for existing docker-compose.yml on VPS
|
|
log_step "Checking for docker-compose.yml..."
|
|
if ! ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "test -f $COMPOSE_FILE"; then
|
|
log_warn "No docker-compose.yml found at $COMPOSE_FILE"
|
|
log_step "Checking for alternatives..."
|
|
|
|
# Try common locations
|
|
for ALT in "/opt/lilith-platform/infrastructure/docker/docker-compose.prod.yml" \
|
|
"/opt/lilith-platform/docker-compose.prod.yml" \
|
|
"/root/lilith-platform/docker-compose.yml"; do
|
|
if ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "test -f $ALT" 2>/dev/null; then
|
|
COMPOSE_FILE="$ALT"
|
|
log_success "Found: $COMPOSE_FILE"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# Start containers
|
|
log_step "Starting containers..."
|
|
echo ""
|
|
|
|
# Method 1: Try docker compose
|
|
if ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "test -f $COMPOSE_FILE" 2>/dev/null; then
|
|
echo -e "Using docker compose from: ${COLOR_BLUE}$COMPOSE_FILE${COLOR_NC}"
|
|
COMPOSE_DIR=$(dirname "$COMPOSE_FILE")
|
|
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "cd $COMPOSE_DIR && docker compose -f $(basename $COMPOSE_FILE) up -d"
|
|
else
|
|
# Method 2: Start containers that are stopped but exist
|
|
log_warn "No compose file found, starting existing stopped containers..."
|
|
STOPPED=$(ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker ps -a --filter 'status=exited' -q")
|
|
if [ -n "$STOPPED" ]; then
|
|
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker start \$(docker ps -a --filter 'status=exited' -q)"
|
|
else
|
|
log_warn "No stopped containers found."
|
|
echo "You may need to run docker compose manually on the VPS."
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Wait for health checks
|
|
log_step "Waiting for containers to be healthy (30s timeout)..."
|
|
sleep 5
|
|
|
|
# Check final state
|
|
for i in {1..5}; do
|
|
UNHEALTHY=$(ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker ps --filter 'health=unhealthy' -q | wc -l" 2>/dev/null || echo "0")
|
|
STARTING=$(ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker ps --filter 'health=starting' -q | wc -l" 2>/dev/null || echo "0")
|
|
|
|
if [ "$STARTING" -eq 0 ]; then
|
|
break
|
|
fi
|
|
sleep 5
|
|
done
|
|
|
|
echo ""
|
|
log_step "Final container state:"
|
|
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker ps --format 'table {{.Names}}\t{{.Status}}'" || true
|
|
|
|
echo ""
|
|
log_section "Spinup complete!"
|
|
echo ""
|
|
echo -e "Run ${COLOR_YELLOW}run infra status${COLOR_NC} to check service health"
|