#!/usr/bin/env bash # Start all three Quarkus modules in dev mode. # Uses tmux (one window per module) if available; falls back to background processes. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" LOG_DIR="$PROJECT_ROOT/.logs" PID_DIR="$PROJECT_ROOT/.pids" GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m' info() { echo -e "${GREEN}[apix]${NC} $*"; } warn() { echo -e "${YELLOW}[warn]${NC} $*"; } mkdir -p "$LOG_DIR" "$PID_DIR" cd "$PROJECT_ROOT" # Require PostgreSQL if ! docker ps --format '{{.Names}}' | grep -qx apix-postgres; then echo "PostgreSQL container is not running." echo "Run: ./scripts/setup-dev.sh" read -rp "Press Enter to close…" _ exit 1 fi # ── tmux mode ──────────────────────────────────────────────────────────────── if command -v tmux &>/dev/null; then SESSION=apix-dev if tmux has-session -t "$SESSION" 2>/dev/null; then warn "tmux session '$SESSION' already exists." echo " Attach: tmux attach -t $SESSION" echo " Restart: ./scripts/restart.sh" exit 0 fi tmux new-session -d -s "$SESSION" -x 220 -y 50 -n registry tmux send-keys -t "$SESSION:registry" \ "cd '$PROJECT_ROOT' && mvn quarkus:dev -pl apix-registry" Enter tmux new-window -t "$SESSION" -n portal tmux send-keys -t "$SESSION:portal" \ "cd '$PROJECT_ROOT' && mvn quarkus:dev -pl apix-portal" Enter tmux new-window -t "$SESSION" -n spider tmux send-keys -t "$SESSION:spider" \ "cd '$PROJECT_ROOT' && mvn quarkus:dev -pl apix-spider" Enter tmux select-window -t "$SESSION:registry" echo "" echo -e "${GREEN}Started in tmux session '${SESSION}'${NC}" echo " Switch windows: Ctrl-b 0 / 1 / 2" echo " Detach: Ctrl-b d" echo "" echo " Registry API → http://localhost:8180" echo " Portal → http://localhost:8081" echo "" tmux attach -t "$SESSION" exit 0 fi # ── Background mode (no tmux) ───────────────────────────────────────────────── warn "tmux not found — starting modules in background with log files." _start() { local module="$1" port="$2" local pidfile="$PID_DIR/${module}.pid" local logfile="$LOG_DIR/${module}.log" if [[ -f "$pidfile" ]] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then info "$module already running (PID $(cat "$pidfile"))" return fi info "Starting $module → http://localhost:${port}" MAVEN_OPTS="-XX:TieredStopAtLevel=1" \ mvn quarkus:dev -pl "$module" >"$logfile" 2>&1 & echo $! >"$pidfile" } _start apix-registry 8180 _start apix-portal 8081 _start apix-spider 8082 echo "" echo -e "${GREEN}All modules started${NC}" echo " Logs: ./scripts/logs.sh [registry|portal|spider|all]" echo " Stop: ./scripts/stop.sh" echo "" echo " Registry API → http://localhost:8180" echo " Portal → http://localhost:8081" echo "" read -rp "Press Enter to close…" _