diff --git a/AGENTS.md b/AGENTS.md index 0acfb07f..909c656f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -47,12 +47,13 @@ Rust-based digital asset management system with video analysis and RAG capabilit ### 日誌與啟動 | 服務 | 日誌路徑 | 啟動方式 | |------|----------|----------| -| Production (3002) | `logs/momentry_3002.log` | `./run-server-3002.sh` | +| Production (3002) | `logs/momentry_3002.log` | **launchd** (`com.momentry.server` + `com.momentry.worker`) | | Playground (3003) | `logs/momentry_3003.log` | `./run-server-3003.sh` | -| Worker / 歷史 | `logs/nohup_worker_*.log` | 由 worker 自動產生 | +| Worker / 歷史 | `logs/worker_3002.log` | 由 launchd worker 寫入 | > **注意**: 所有伺服器日誌統一存放於專案內 `logs/` 目錄。 -> 啟動腳本會自動 kill 舊程序、重 build(若需要)、並將日誌導向 `logs/`。 +> **Production (3002) 正式部署由 launchd 管理**(`~/Library/LaunchAgents/com.momentry.server.plist` + `com.momentry.worker.plist`),兩者皆使用 `target/release/momentry`,KeepAlive 自動重啟。`run-server-3002.sh` 僅供開發時臨時手動啟動(會與 launchd 衝突,勿與 launchd 並用)。 +> **⚠️ 啟動 launchd worker 若未註冊**:`launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.momentry.worker.plist`(不是 `load`),worker plist 的 VLM 指向 gemma 8080(8091 已停用)。 ## ⚠️ 交叉污染防制 (Cross-Contamination Prevention) @@ -215,8 +216,11 @@ cargo run -- server --host 0.0.0.0 --port 3002 cargo run --bin momentry_playground -- server cargo run --bin momentry_playground -- --help -# Start servers (recommended — auto-build & logs to logs/) -./run-server-3002.sh +# Start servers (recommended — production via launchd, dev via scripts) +# Production (3002) is managed by launchd: com.momentry.server + com.momentry.worker +# launchctl start gui/$(id -u)/com.momentry.server +# launchctl start gui/$(id -u)/com.momentry.worker +# (run-server-3002.sh is dev-only and conflicts with launchd — do NOT mix) ./run-server-3003.sh ``` diff --git a/run-server-3002.sh b/run-server-3002.sh index 3fcbf6bf..7665d3f9 100755 --- a/run-server-3002.sh +++ b/run-server-3002.sh @@ -1,22 +1,34 @@ #!/usr/bin/env bash -# Start production server (port 3002) +# Start production server (port 3002) — DEV/EMERGENCY use only. +# NOTE: Production is normally managed by launchd (com.momentry.server + com.momentry.worker). +# Running this script while launchd agents are loaded creates duplicate processes. +# Use it only to temporarily run outside launchd (e.g. debugging), and stop launchd agents first. set -euo pipefail cd /Users/accusys/momentry_core +# Binary selection: default to release binary (production); override with +# MOMENTRY_PROD_BIN=debug to run the debug build instead. +BIN="${MOMENTRY_PROD_BIN:-release}" +MOMENTRY_BIN="target/${BIN}/momentry" +if [ ! -f "$MOMENTRY_BIN" ]; then + echo "Binary not found: $MOMENTRY_BIN (build it first or set MOMENTRY_PROD_BIN=debug)" >&2 + exit 1 +fi + # Kill existing processes -pkill -f "target/debug/momentry server" 2>/dev/null || true -pkill -f "target/debug/momentry worker" 2>/dev/null || true +pkill -f "momentry server" 2>/dev/null || true +pkill -f "momentry worker" 2>/dev/null || true sleep 2 # Start server -echo "Starting server on port 3002..." +echo "Starting server on port 3002 (binary: $MOMENTRY_BIN)..." export MOMENTRY_SERVER_PORT=3002 export MOMENTRY_REDIS_PREFIX=momentry: export DATABASE_SCHEMA=public export MOMENTRY_OUTPUT_DIR=/Users/accusys/momentry/output -nohup ./target/debug/momentry server > logs/momentry_3002.log 2>&1 & +nohup "$MOMENTRY_BIN" server > logs/momentry_3002.log 2>&1 & SERVER_PID=$! echo "Server PID: $SERVER_PID" @@ -24,7 +36,7 @@ sleep 2 # Start worker echo "Starting worker with max_concurrent=6..." -nohup ./target/debug/momentry worker \ +nohup "$MOMENTRY_BIN" worker \ --max-concurrent 6 \ --poll-interval 5 \ --batch-size 10 \