fix: production service auto-start via launchd + fix worker retry loop

- Replaced old wrapper script with two launchd plists (server + worker)
- Both services auto-start at login via RunAtLoad + KeepAlive
- Removed MOMENTRY_FORCE_RETRY=true from .env to prevent infinite retries
- Added REDIS_URL and all required env vars to launchd plists
- Truncated 3.6GB of oversized logs (2.3G worker + 1.3G launchd stdout)
- Deleted 1214 orphaned processor_results records
- Updated run-server-3002.sh to manage via launchctl
- Removed obsolete wrapper scripts
This commit is contained in:
Accusys
2026-07-07 05:41:09 +08:00
parent bb606f52f5
commit 149226ff17
+27 -53
View File
@@ -1,56 +1,30 @@
#!/usr/bin/env bash
# Start production server on port 3002
# Logs to logs/momentry_3002.log
# Start production server via launchd
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Production environment variables
export MOMENTRY_OUTPUT_DIR=/Users/accusys/momentry/output
export DATABASE_SCHEMA=public
export MOMENTRY_REDIS_PREFIX=momentry:
export MOMENTRY_SERVER_PORT=3002
# Qdrant credentials for Python subprocesses
export QDRANT_URL=http://127.0.0.1:6333
export QDRANT_API_KEY=Test3200Test3200Test3200
# Kill existing server on port 3002
PID=$(lsof -ti :3002 2>/dev/null || true)
if [ -n "$PID" ]; then
echo "Killing existing server on port 3002 (PID: $PID)"
kill "$PID" 2>/dev/null || true
sleep 2
fi
# Kill existing worker via PID file
if [ -f logs/worker_3002.pid ]; then
WPID=$(cat logs/worker_3002.pid)
if kill -0 "$WPID" 2>/dev/null; then
echo "Killing existing worker (PID: $WPID)"
kill "$WPID" 2>/dev/null || true
sleep 1
fi
rm -f logs/worker_3002.pid
fi
# Build if needed
if [ ! -f target/release/momentry ]; then
echo "Building release binary..."
cargo build --release --bin momentry
fi
# Start server
echo "Starting momentry server on port 3002..."
./target/release/momentry server --host 0.0.0.0 --port 3002 > logs/momentry_3002.log 2>&1 &
echo "Server started (PID: $!)"
echo "Logs: logs/momentry_3002.log"
# Start companion worker
echo "Starting momentry worker..."
nohup ./target/release/momentry worker --max-concurrent 6 --poll-interval 10 --batch-size 5 > logs/worker_3002.log 2>&1 &
WPID=$!
echo "$WPID" > logs/worker_3002.pid
echo "Worker started (PID: $WPID)"
echo "Worker logs: logs/worker_3002.log"
case "${1:-}" in
stop)
echo "Stopping production server and worker..."
launchctl bootout gui/$(id -u)/com.momentry.server 2>/dev/null || true
launchctl bootout gui/$(id -u)/com.momentry.worker 2>/dev/null || true
echo "Stopped."
;;
restart)
exec "$0" stop
exec "$0" start
;;
status)
echo "=== Server ==="
launchctl list com.momentry.server 2>/dev/null | head -5 || echo "Not loaded"
echo "=== Worker ==="
launchctl list com.momentry.worker 2>/dev/null | head -5 || echo "Not loaded"
echo "=== Health ==="
curl -s --max-time 3 http://localhost:3002/api/v1/health 2>/dev/null || echo "No response"
;;
*)
echo "Starting production server and worker via launchd..."
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.momentry.server.plist 2>/dev/null || launchctl load ~/Library/LaunchAgents/com.momentry.server.plist
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.momentry.worker.plist 2>/dev/null || launchctl load ~/Library/LaunchAgents/com.momentry.worker.plist
echo "Done. Use '$0 status' to check."
;;
esac