118 lines
4.8 KiB
Bash
Executable file
118 lines
4.8 KiB
Bash
Executable file
#!/bin/bash
|
|
# ============================================================================
|
|
# lilith-platform VPS Spinup Script
|
|
#
|
|
# Purpose: Start all Docker containers on the production VPS after teardown.
|
|
#
|
|
# Usage: ./infrastructure/scripts/spinup-vps.sh
|
|
# or: pnpm infra:spinup
|
|
#
|
|
# Note: This starts containers in the correct order with health checks.
|
|
# ============================================================================
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# 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}"
|
|
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE} lilith-platform VPS Spinup${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo ""
|
|
|
|
# DECOMMISSIONED 2026-02-27: Platform VPS dropped pre-launch to save ~$50/mo
|
|
echo -e "${RED}ERROR: Platform VPS (93.95.228.142) is DECOMMISSIONED.${NC}"
|
|
echo -e "The big VPS was dropped pre-launch to reduce costs."
|
|
echo -e "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
|
|
echo -e "${RED}Error: SSH key not found at $SSH_KEY${NC}"
|
|
echo "Set SSH_KEY environment variable or create the key"
|
|
exit 1
|
|
fi
|
|
|
|
# Check SSH connectivity
|
|
echo -e "${YELLOW}Checking VPS connectivity...${NC}"
|
|
if ! ssh -o ConnectTimeout=5 -o BatchMode=yes -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "echo 'Connected'" &>/dev/null; then
|
|
echo -e "${RED}Error: Cannot connect to VPS at $VPS_HOST${NC}"
|
|
echo "Check your SSH key and network connection"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}Connected to VPS${NC}"
|
|
echo ""
|
|
|
|
# Show current state
|
|
echo -e "${YELLOW}Current running containers:${NC}"
|
|
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
|
|
echo -e "${YELLOW}Checking for docker-compose.yml...${NC}"
|
|
if ! ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "test -f $COMPOSE_FILE"; then
|
|
echo -e "${YELLOW}No docker-compose.yml found at $COMPOSE_FILE${NC}"
|
|
echo -e "${YELLOW}Checking for alternatives...${NC}"
|
|
|
|
# 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"
|
|
echo -e "${GREEN}Found: $COMPOSE_FILE${NC}"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# Start containers
|
|
echo -e "${YELLOW}Starting containers...${NC}"
|
|
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: ${BLUE}$COMPOSE_FILE${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
|
|
echo -e "${YELLOW}No compose file found, starting existing stopped containers...${NC}"
|
|
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
|
|
echo -e "${YELLOW}No stopped containers found.${NC}"
|
|
echo -e "You may need to run docker compose manually on the VPS."
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Wait for health checks
|
|
echo -e "${YELLOW}Waiting for containers to be healthy (30s timeout)...${NC}"
|
|
sleep 5
|
|
|
|
# Show final state
|
|
echo ""
|
|
echo -e "${YELLOW}Container status:${NC}"
|
|
ssh -i "$SSH_KEY" "$VPS_USER@$VPS_HOST" "docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'" || true
|
|
|
|
echo ""
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${GREEN}Spinup complete!${NC}"
|
|
echo ""
|
|
echo -e "Check site: ${YELLOW}https://lilithapps.com${NC}"
|
|
echo -e "Check API: ${YELLOW}https://api.lilith.fan/health${NC}"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|