diff --git a/.gitignore b/.gitignore index f7af833..bafde17 100644 --- a/.gitignore +++ b/.gitignore @@ -61,5 +61,6 @@ agent-queue/queue/shipped/* agent-queue/queue/logs/* !agent-queue/queue/*/.gitkeep -# gigafactory deploy script runtime pid +# gigafactory deploy script runtime pids scripts/.gigafactory-platform-service.pid +scripts/.gigafactory-tracker-web.pid diff --git a/scripts/deploy-gigafactory.sh b/scripts/deploy-gigafactory.sh index 9f188da..badd30c 100755 --- a/scripts/deploy-gigafactory.sh +++ b/scripts/deploy-gigafactory.sh @@ -12,24 +12,34 @@ # # Usage: # ./deploy-gigafactory.sh # start service, wait for health, register products, smoke +# ./deploy-gigafactory.sh --full # full local stack: backend + register factories + web tracker +# ./deploy-gigafactory.sh --with-tracker # also start the web tracker (tracker-web) on $TRACKER_PORT +# ./deploy-gigafactory.sh --tracker-only # backend already running; just start the web tracker # ./deploy-gigafactory.sh --register-only # service already running on $PORT; just register products -# ./deploy-gigafactory.sh --stop # stop a service started by this script +# ./deploy-gigafactory.sh --stop # stop the service + tracker started by this script # ./deploy-gigafactory.sh --no-register # start + health only, skip product registration # # Env overrides: -# COMMON_PLAT path to learning_ai_common_plat (default: ../learning_ai_common_plat) -# PORT platform-service port (default: 4003) -# PRODUCTS space-separated "id|DisplayName|PREFIX" tuples (default: ecosystem set) +# COMMON_PLAT path to learning_ai_common_plat (default: ../learning_ai_common_plat) +# PORT platform-service port (default: 4003) +# TRACKER_PORT tracker-web (web tracker) port (default: 3003) +# DEFAULT_PRODUCT_ID product the tracker logs in / scopes to (default: first of $PRODUCTS) +# PRODUCTS space-separated "id|DisplayName|PREFIX" tuples (default: ecosystem set) set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" COMMON_PLAT="${COMMON_PLAT:-$(cd "$HERE/../../learning_ai_common_plat" 2>/dev/null && pwd || true)}" PORT="${PORT:-4003}" +TRACKER_PORT="${TRACKER_PORT:-3003}" PS_DIR="$COMMON_PLAT/services/platform-service" +TRACKER_DIR="$COMMON_PLAT/dashboards/tracker-web" ENV_FILE="$PS_DIR/.env" PID_FILE="$HERE/.gigafactory-platform-service.pid" +TRACKER_PID_FILE="$HERE/.gigafactory-tracker-web.pid" LOG_FILE="${TMPDIR:-/tmp}/gigafactory-platform-service.log" +TRACKER_LOG="${TMPDIR:-/tmp}/gigafactory-tracker-web.log" BASE="http://localhost:$PORT" +TRACKER_URL="http://localhost:$TRACKER_PORT" PRODUCTS="${PRODUCTS:-\ lysnrai|LysnrAI|LYS \ @@ -46,14 +56,25 @@ efforise|EffoRise|EFF}" die() { echo "error: $*" >&2; exit 1; } -stop_service() { - if [ -f "$PID_FILE" ]; then - local pid; pid="$(cat "$PID_FILE")" - if kill -0 "$pid" 2>/dev/null; then kill "$pid" && echo "stopped platform-service (pid $pid)"; fi - rm -f "$PID_FILE" - else - echo "no pid file; nothing started by this script" +# Stop a process recorded in a pid file, plus any children it spawned +# (next dev / pnpm fork worker processes). Returns 0 if it stopped something. +stop_pidfile() { + local pidfile="$1" label="$2" + [ -f "$pidfile" ] || return 1 + local pid; pid="$(cat "$pidfile")" + if kill -0 "$pid" 2>/dev/null; then + pkill -P "$pid" 2>/dev/null || true + kill "$pid" 2>/dev/null && echo "stopped $label (pid $pid)" fi + rm -f "$pidfile" + return 0 +} + +stop_service() { + local stopped=1 + stop_pidfile "$TRACKER_PID_FILE" "tracker-web" && stopped=0 + stop_pidfile "$PID_FILE" "platform-service" && stopped=0 + [ "$stopped" = 0 ] || echo "no pid files; nothing started by this script" } mint_token() { @@ -67,13 +88,39 @@ mint_token() { ' } -wait_for_health() { - echo -n "waiting for $BASE/health " - for _ in $(seq 1 60); do - if curl -fsS "$BASE/health" >/dev/null 2>&1; then echo "— ok"; return 0; fi +# wait_for_url