#!/bin/bash set -e # ─────────────────────────────────────────────────────────────────── # VM Bench Frontend — Installer for vm-bench LXC # # Run: bash /mnt/converter/frontend/install.sh # # Installs system tools, Python dependencies, and the systemd # service that serves the web UI on port 5000. # ─────────────────────────────────────────────────────────────────── RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' NC='\033[0m' SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SERVICE_NAME="vm-bench" SERVICE_FILE="${SCRIPT_DIR}/${SERVICE_NAME}.service" SYSTEMD_DIR="/etc/systemd/system" echo "" echo "╔════════════════════════════════════════════╗" echo "║ VM Bench Frontend Installer (LXC) ║" echo "╚════════════════════════════════════════════╝" echo "" # ─────────────────────────────────────────────────────────────────── # Step 1: System packages # ─────────────────────────────────────────────────────────────────── echo "[1/5] Checking system packages..." PACKAGES=() REQUIRED=( python3 "python3" python3-pip "pip3" wget "wget" curl "curl" openssh-client "scp" sshpass "sshpass" ) for ((i=0; i<${#REQUIRED[@]}; i+=2)); do pkg="${REQUIRED[$i]}" bin="${REQUIRED[$i+1]}" if command -v "$bin" &>/dev/null; then echo " ${GREEN}✓${NC} $bin" else echo " ${YELLOW}○${NC} $bin (will install ${pkg})" PACKAGES+=("$pkg") fi done if [ ${#PACKAGES[@]} -gt 0 ]; then echo "" echo " Installing missing packages: ${PACKAGES[*]}" apt-get update -qq apt-get install -y -qq "${PACKAGES[@]}" echo " ${GREEN}✓${NC} System packages installed." else echo " ${GREEN}✓${NC} All system packages present." fi # ─────────────────────────────────────────────────────────────────── # Step 2: Python dependencies # ─────────────────────────────────────────────────────────────────── echo "" echo "[2/5] Installing Python dependencies..." cd "$SCRIPT_DIR" python3 -m pip install --break-system-packages -r requirements.txt -q echo " ${GREEN}✓${NC} Python dependencies installed." # ─────────────────────────────────────────────────────────────────── # Step 3: Verify backend connectivity # ─────────────────────────────────────────────────────────────────── echo "" echo "[3/5] Checking backend connectivity..." BACKEND_URL="${BACKEND_URL:-http://10.2.0.2:9000}" if curl -sf --max-time 5 "${BACKEND_URL}/api/v1/health" > /dev/null 2>&1; then echo " ${GREEN}✓${NC} Backend reachable at $BACKEND_URL" else echo " ${YELLOW}!${NC} Backend not reachable at $BACKEND_URL" echo " The frontend will start, but conversion jobs will fail until the" echo " backend is running on srv2. You can change BACKEND_URL in" echo " ${SYSTEMD_DIR}/${SERVICE_NAME}.service" fi # ─────────────────────────────────────────────────────────────────── # Step 4: Systemd service # ─────────────────────────────────────────────────────────────────── echo "" echo "[4/5] Installing systemd service..." if [ ! -f "$SERVICE_FILE" ]; then echo " ${RED}✗${NC} Service file not found: $SERVICE_FILE" exit 1 fi cp "$SERVICE_FILE" "$SYSTEMD_DIR/${SERVICE_NAME}.service" systemctl daemon-reload systemctl enable "$SERVICE_NAME" echo " ${GREEN}✓${NC} Service installed and enabled." # ─────────────────────────────────────────────────────────────────── # Step 5: Start & verify # ─────────────────────────────────────────────────────────────────── echo "" echo "[5/5] Starting service..." systemctl restart "$SERVICE_NAME" sleep 2 if systemctl is-active --quiet "$SERVICE_NAME"; then echo " ${GREEN}✓${NC} Frontend is RUNNING on port 5000" echo "" echo " Open: http://$(hostname -I 2>/dev/null | awk '{print $1}'):5000" echo " Verify: curl http://127.0.0.1:5000" echo " Logs: journalctl -u ${SERVICE_NAME} -f" echo " Status: systemctl status ${SERVICE_NAME}" else echo " ${RED}✗${NC} Service failed to start. Check logs:" echo " journalctl -u ${SERVICE_NAME} -n 30" exit 1 fi echo "" echo "╔════════════════════════════════════════════╗" echo "║ ${GREEN}Frontend installation complete.${NC} ║" echo "╚════════════════════════════════════════════╝" echo ""