#!/usr/bin/env bash # Restart one or all dev-mode Quarkus modules. # Usage: restart.sh [registry|portal|spider|all] (default: all) set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" PID_DIR="$PROJECT_ROOT/.pids" LOG_DIR="$PROJECT_ROOT/.logs" TARGET="${1:-all}" GREEN='\033[0;32m'; NC='\033[0m' info() { echo -e "${GREEN}[apix]${NC} $*"; } # ── tmux mode ──────────────────────────────────────────────────────────────── if command -v tmux &>/dev/null && tmux has-session -t apix-dev 2>/dev/null; then _restart_window() { local win="$1" cmd="$2" tmux send-keys -t "apix-dev:${win}" C-c '' ENTER sleep 0.5 tmux send-keys -t "apix-dev:${win}" "cd '$PROJECT_ROOT' && $cmd" ENTER info "Restarted $win" } case "$TARGET" in registry) _restart_window registry "mvn quarkus:dev -pl apix-registry" ;; portal) _restart_window portal "mvn quarkus:dev -pl apix-portal" ;; spider) _restart_window spider "mvn quarkus:dev -pl apix-spider" ;; all) _restart_window registry "mvn quarkus:dev -pl apix-registry" _restart_window portal "mvn quarkus:dev -pl apix-portal" _restart_window spider "mvn quarkus:dev -pl apix-spider" ;; *) echo "Usage: restart.sh [registry|portal|spider|all]"; exit 1 ;; esac exit 0 fi # ── Background mode ─────────────────────────────────────────────────────────── _kill_module() { local module="$1" local pidfile="$PID_DIR/${module}.pid" if [[ -f "$pidfile" ]]; then local pid pid=$(cat "$pidfile") if kill -0 "$pid" 2>/dev/null; then info "Stopping $module (PID $pid)" kill "$pid" 2>/dev/null || true sleep 1 fi rm -f "$pidfile" fi } _start_module() { local module="$1" port="$2" local pidfile="$PID_DIR/${module}.pid" local logfile="$LOG_DIR/${module}.log" info "Starting $module → http://localhost:${port}" MAVEN_OPTS="-XX:TieredStopAtLevel=1" \ mvn quarkus:dev -pl "$module" >"$logfile" 2>&1 & echo $! >"$pidfile" } case "$TARGET" in registry) _kill_module apix-registry _start_module apix-registry 8180 ;; portal) _kill_module apix-portal _start_module apix-portal 8081 ;; spider) _kill_module apix-spider _start_module apix-spider 8082 ;; all) _kill_module apix-registry; _kill_module apix-portal; _kill_module apix-spider _start_module apix-registry 8180 _start_module apix-portal 8081 _start_module apix-spider 8082 ;; *) echo "Usage: restart.sh [registry|portal|spider|all]"; exit 1 ;; esac