fix: add environment variable exports to startup scripts
- Added MOMENTRY_OUTPUT_DIR, DATABASE_SCHEMA, MOMENTRY_REDIS_PREFIX exports - Created run-worker-3002.sh for standalone worker - Created config/ directory with environment-specific files - Updated AGENTS.md with critical variables section and release checklist This fixes Python subprocess environment variable inheritance issue where store_traced_faces.py was using wrong output directory.
This commit is contained in:
44
AGENTS.md
44
AGENTS.md
@@ -407,6 +407,40 @@ cargo run --features player --bin momentry_player -- -o
|
||||
- `MOMENTRY_PYTHON_PATH` - Python path (default: `/opt/homebrew/bin/python3.11`)
|
||||
- `MOMENTRY_SCRIPTS_DIR` - Scripts directory
|
||||
|
||||
### Critical Variables for Startup Scripts
|
||||
|
||||
**IMPORTANT**: Startup scripts must explicitly `export` these variables for Python subprocess inheritance.
|
||||
|
||||
#### Production (3002)
|
||||
Required exports in `run-server-3002.sh` and `run-worker-3002.sh`:
|
||||
```bash
|
||||
export MOMENTRY_OUTPUT_DIR=/Users/accusys/momentry/output
|
||||
export DATABASE_SCHEMA=public
|
||||
export MOMENTRY_REDIS_PREFIX=momentry:
|
||||
export MOMENTRY_SERVER_PORT=3002
|
||||
```
|
||||
|
||||
#### Playground (3003)
|
||||
Required exports in `run-server-3003.sh`:
|
||||
```bash
|
||||
export DATABASE_SCHEMA=dev
|
||||
export MOMENTRY_SERVER_PORT=3003
|
||||
export MOMENTRY_REDIS_PREFIX=momentry_dev:
|
||||
export MOMENTRY_OUTPUT_DIR=/Users/accusys/momentry/output_dev
|
||||
```
|
||||
|
||||
#### Why This Matters
|
||||
- Rust process loads `.env` via `dotenv`
|
||||
- Python subprocess inherits environment from Rust process
|
||||
- Without explicit `export`, dotenv variables are only available inside Rust
|
||||
- Python scripts like `store_traced_faces.py` will use hardcoded defaults if not exported
|
||||
|
||||
#### Config Directory
|
||||
Environment-specific configuration files:
|
||||
- `config/production.env` - Production-specific variables
|
||||
- `config/development.env` - Development-specific variables
|
||||
- `config/test.env` - Test environment (if needed)
|
||||
|
||||
### Processor Timeouts
|
||||
- `MOMENTRY_ASR_TIMEOUT` - ASR timeout in seconds (default: 3600)
|
||||
- `MOMENTRY_CUT_TIMEOUT` - CUT timeout in seconds (default: 3600)
|
||||
@@ -625,6 +659,16 @@ git push origin main
|
||||
pg_dump -U accusys -d momentry --schema-only > "$RELEASE_DIR/schema_v0.X.X.sql"
|
||||
```
|
||||
|
||||
5. **驗證環境變數配置**
|
||||
- ✅ Startup scripts export all required environment variables
|
||||
- ✅ Python scripts don't use hardcoded paths
|
||||
- ✅ Environment variables consistent across:
|
||||
- `.env` / `.env.development`
|
||||
- Startup script `export`
|
||||
- Python script `os.environ.get()`
|
||||
- ✅ Config directory has environment-specific files
|
||||
- ✅ AGENTS.md documents all required exports
|
||||
|
||||
### 重要性
|
||||
- 避免 release binary 與 current source code 不一致
|
||||
- 方便追蹤特定 release 的程式碼狀態
|
||||
|
||||
47
config/development.env
Normal file
47
config/development.env
Normal file
@@ -0,0 +1,47 @@
|
||||
# Development Environment Configuration
|
||||
# Used by: momentry_playground binary on port 3003
|
||||
#
|
||||
# This file extracts development-specific variables from .env.development
|
||||
# Startup scripts must export these variables for Python subprocess inheritance
|
||||
|
||||
# Server Configuration
|
||||
MOMENTRY_SERVER_PORT=3003
|
||||
MOMENTRY_REDIS_PREFIX=momentry_dev:
|
||||
|
||||
# Database Schema
|
||||
DATABASE_SCHEMA=dev
|
||||
|
||||
# Output Directory (CRITICAL for Python scripts)
|
||||
MOMENTRY_OUTPUT_DIR=/Users/accusys/momentry/output_dev
|
||||
|
||||
# Backup Directory
|
||||
MOMENTRY_BACKUP_DIR=/Users/accusys/momentry/backup/momentry_dev
|
||||
|
||||
# Storage
|
||||
MOMENTRY_SFTP_ROOT=/Users/accusys/momentry/var/sftpgo/data/demo/
|
||||
|
||||
# Python Path (venv for development)
|
||||
MOMENTRY_PYTHON_PATH=/Users/accusys/momentry_core/venv/bin/python
|
||||
MOMENTRY_SCRIPTS_DIR=/Users/accusys/momentry_core/scripts
|
||||
|
||||
# Logging
|
||||
RUST_LOG=info
|
||||
MOMENTRY_LOG_LEVEL=info
|
||||
|
||||
# Worker Configuration
|
||||
MOMENTRY_WORKER_ENABLED=true
|
||||
MOMENTRY_MAX_CONCURRENT=6
|
||||
MOMENTRY_POLL_INTERVAL=10
|
||||
MOMENTRY_WORKER_BATCH_SIZE=5
|
||||
|
||||
# TMDb Integration
|
||||
TMDB_API_KEY=e9cde52197f6f8df4d9db99da93db1fb
|
||||
MOMENTRY_TMDB_PROBE_ENABLED=true
|
||||
|
||||
# LLM Configuration
|
||||
MOMENTRY_LLM_SUMMARY_URL=http://127.0.0.1:8000/v1/chat/completions
|
||||
MOMENTRY_LLM_SUMMARY_MODEL=gemma-4-E4B
|
||||
MOMENTRY_LLM_SUMMARY_ENABLED=true
|
||||
|
||||
# Embedding
|
||||
MOMENTRY_EMBED_URL=http://localhost:11436
|
||||
39
config/production.env
Normal file
39
config/production.env
Normal file
@@ -0,0 +1,39 @@
|
||||
# Production Environment Configuration
|
||||
# Used by: momentry binary on port 3002
|
||||
#
|
||||
# This file extracts production-specific variables from .env
|
||||
# Startup scripts must export these variables for Python subprocess inheritance
|
||||
|
||||
# Server Configuration
|
||||
MOMENTRY_SERVER_PORT=3002
|
||||
MOMENTRY_REDIS_PREFIX=momentry:
|
||||
|
||||
# Database Schema
|
||||
DATABASE_SCHEMA=public
|
||||
|
||||
# Output Directory (CRITICAL for Python scripts)
|
||||
MOMENTRY_OUTPUT_DIR=/Users/accusys/momentry/output
|
||||
|
||||
# Backup Directory
|
||||
MOMENTRY_BACKUP_DIR=/Users/accusys/momentry/backup/momentry
|
||||
|
||||
# Storage
|
||||
MOMENTRY_STORAGE_ROOT=/Users/accusys/momentry/var/sftpgo/data
|
||||
|
||||
# Python Path
|
||||
MOMENTRY_PYTHON_PATH=/opt/homebrew/bin/python3.11
|
||||
|
||||
# Logging
|
||||
RUST_LOG=debug
|
||||
MOMENTRY_LOG_LEVEL=debug
|
||||
|
||||
# Worker Configuration
|
||||
MOMENTRY_WORKER_ENABLED=true
|
||||
MOMENTRY_MAX_CONCURRENT=6
|
||||
MOMENTRY_POLL_INTERVAL=10
|
||||
MOMENTRY_WORKER_BATCH_SIZE=5
|
||||
MOMENTRY_FORCE_RETRY=true
|
||||
|
||||
# TMDb Integration
|
||||
TMDB_API_KEY=e9cde52197f6f8df4d9db99da93db1fb
|
||||
MOMENTRY_TMDB_PROBE_ENABLED=true
|
||||
@@ -7,6 +7,12 @@ 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
|
||||
|
||||
# Kill existing server on port 3002
|
||||
PID=$(lsof -ti :3002 2>/dev/null || true)
|
||||
if [ -n "$PID" ]; then
|
||||
|
||||
@@ -13,6 +13,7 @@ mkdir -p logs
|
||||
export DATABASE_SCHEMA=dev
|
||||
export MOMENTRY_SERVER_PORT=3003
|
||||
export MOMENTRY_REDIS_PREFIX=momentry_dev:
|
||||
export MOMENTRY_OUTPUT_DIR=/Users/accusys/momentry/output_dev
|
||||
|
||||
# Kill existing server on port 3003
|
||||
PID=$(lsof -ti :3003 2>/dev/null || true)
|
||||
|
||||
40
run-worker-3002.sh
Executable file
40
run-worker-3002.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
# Start production worker on port 3002
|
||||
# Logs to logs/worker_3002.log
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
mkdir -p logs
|
||||
|
||||
# Production environment variables
|
||||
export MOMENTRY_OUTPUT_DIR=/Users/accusys/momentry/output
|
||||
export DATABASE_SCHEMA=public
|
||||
export MOMENTRY_REDIS_PREFIX=momentry:
|
||||
|
||||
# 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 worker
|
||||
echo "Starting momentry worker (DATABASE_SCHEMA=${DATABASE_SCHEMA})..."
|
||||
nohup ./target/release/momentry worker > 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"
|
||||
Reference in New Issue
Block a user