start_announcement.sh 1.87 KB
#!/bin/bash

SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
ENV_FILE="$SCRIPT_DIR/../.env.sh"

if [ -f "$ENV_FILE" ]; then
    echo "Loading configuration from $ENV_FILE"
    source "$ENV_FILE"
else
    echo "Error: Configuration file not found at $ENV_FILE"
    exit 1
fi

if [ -z "$LOCAL_FRONTEND_PORT" ]; then
    echo "Error: LOCAL_FRONTEND_PORT is not set in .env.sh"
    exit 1
fi

echo "=================================================="
echo "Starting Maintenance Announcement"
echo "Target Port: $LOCAL_FRONTEND_PORT"
echo "Public Port: ${PUBLIC_FRONTEND_PORT:-Unknown}"
echo "=================================================="

APP_NAME="${FRONTEND_NAME:-z-image-frontend}"

if command -v pm2 &> /dev/null; then
    echo "Stopping main frontend application ($APP_NAME)..."
    pm2 stop "$APP_NAME" 2>/dev/null || echo "Main frontend was not running or could not be stopped."
    
    MAINTENANCE_APP_NAME="maintenance-announcement-beta"
    
    echo "Starting announcement page on port $LOCAL_FRONTEND_PORT..."
    
    if command -v python3 &> /dev/null; then
        pm2 delete "$MAINTENANCE_APP_NAME" 2>/dev/null || true
        
        pm2 start "python3 -m http.server $LOCAL_FRONTEND_PORT" \
            --name "$MAINTENANCE_APP_NAME" \
            --cwd "$SCRIPT_DIR" \
            --watch
            
        echo "Maintenance announcement started."
        pm2 list
    else
        echo "Error: python3 is not available. Please install python3 to run the simple http server."
        exit 1
    fi
else
    echo "Error: pm2 is not installed or not in PATH."
    exit 1
fi

echo "=================================================="
echo "Maintenance page should be visible at:"
echo "http://localhost:$LOCAL_FRONTEND_PORT"
if [ ! -z "$PUBLIC_IP" ] && [ ! -z "$PUBLIC_FRONTEND_PORT" ]; then
    echo "http://$PUBLIC_IP:$PUBLIC_FRONTEND_PORT"
fi
echo "=================================================="