fix: correct service paths, nohup removal, MongoDB graceful fallback, add MariaDB + Caddy to startup
- Fix Qdrant binary path (services/ -> momentry_resources/bin/) - Fix LLM binary/model paths (llama/ -> momentry_resources/llama/, models/ -> models/llm/) - Fix PostgreSQL data path (pgsql/data -> momentry/var/postgresql) - Remove nohup (fails in LaunchDaemon environment) - Add MongoDB graceful fallback with 5s timeout in server.rs - Add MariaDB + Caddy steps to startup script for WordPress - Revert all unrelated changes
This commit is contained in:
@@ -25,8 +25,8 @@ echo ""
|
||||
LOG_DIR="/Users/accusys/momentry/logs"
|
||||
|
||||
# ── 1. PostgreSQL ──
|
||||
echo -e "${YELLOW}[1/7] PostgreSQL${NC}"
|
||||
PG_DATA="/Users/accusys/pgsql/data"
|
||||
echo -e "${YELLOW}[1/9] PostgreSQL${NC}"
|
||||
PG_DATA="/Users/accusys/momentry/var/postgresql"
|
||||
PG_BIN="/Users/accusys/pgsql/18.3/bin"
|
||||
if $PG_BIN/pg_isready -q 2>/dev/null; then
|
||||
echo -e " ${GREEN}✅${NC} already running"
|
||||
@@ -37,7 +37,7 @@ else
|
||||
fi
|
||||
|
||||
# ── 2. Redis ──
|
||||
echo -e "${YELLOW}[2/7] Redis${NC}"
|
||||
echo -e "${YELLOW}[2/9] Redis${NC}"
|
||||
if redis-cli ping 2>/dev/null | grep -q PONG; then
|
||||
echo -e " ${GREEN}✅${NC} already running"
|
||||
else
|
||||
@@ -47,14 +47,15 @@ else
|
||||
fi
|
||||
|
||||
# ── 3. Qdrant ──
|
||||
echo -e "${YELLOW}[3/7] Qdrant${NC}"
|
||||
QDRANT_BIN="${PROJECT_DIR}/services/qdrant/target/release/qdrant"
|
||||
echo -e "${YELLOW}[3/9] Qdrant${NC}"
|
||||
QDRANT_BIN="/Users/accusys/momentry_resources/bin/qdrant"
|
||||
QDRANT_STORAGE="/Users/accusys/momentry/qdrant_storage"
|
||||
if curl -s -o /dev/null -w "%{http_code}" --connect-timeout 3 http://localhost:6333/healthz 2>/dev/null | grep -q 200; then
|
||||
echo -e " ${GREEN}✅${NC} already running"
|
||||
else
|
||||
mkdir -p "$QDRANT_STORAGE"
|
||||
nohup "$QDRANT_BIN" > "$LOG_DIR/qdrant.log" 2>&1 &
|
||||
cd "$QDRANT_STORAGE" && "$QDRANT_BIN" > "$LOG_DIR/qdrant.log" 2>&1 &
|
||||
cd "$PROJECT_DIR"
|
||||
for i in $(seq 1 15); do
|
||||
sleep 2
|
||||
if curl -s -o /dev/null -w "%{http_code}" --connect-timeout 2 http://localhost:6333/healthz 2>/dev/null | grep -q 200; then
|
||||
@@ -65,7 +66,7 @@ else
|
||||
fi
|
||||
|
||||
# ── 4. Qdrant Collection ──
|
||||
echo -e "${YELLOW}[4/7] Qdrant Collection${NC}"
|
||||
echo -e "${YELLOW}[4/9] Qdrant Collection${NC}"
|
||||
source "$ENV_FILE" 2>/dev/null || true
|
||||
COLLECTION="${QDRANT_COLLECTION:-momentry_dev_rule1_v2}"
|
||||
EXISTS=$(curl -s "http://localhost:6333/collections/$COLLECTION" 2>/dev/null | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('result',{}).get('status','not_found'))" 2>/dev/null)
|
||||
@@ -79,13 +80,13 @@ curl -s "http://localhost:6333/collections/$COLLECTION" 2>/dev/null | python3 -c
|
||||
check "collection '$COLLECTION' ready"
|
||||
|
||||
# ── 5. LLM (Gemma4 / llama.cpp) ──
|
||||
echo -e "${YELLOW}[5/7] LLM Server (Gemma4)${NC}"
|
||||
echo -e "${YELLOW}[5/9] LLM Server (Gemma4)${NC}"
|
||||
if curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 http://localhost:8082/health 2>/dev/null | grep -q 200; then
|
||||
echo -e " ${GREEN}✅${NC} already running"
|
||||
else
|
||||
LLM_BIN="/Users/accusys/llama/bin/llama-server"
|
||||
LLM_MODEL="/Users/accusys/models/google_gemma-4-26B-A4B-it-Q5_K_M.gguf"
|
||||
nohup "$LLM_BIN" -m "$LLM_MODEL" --host 0.0.0.0 --port 8082 -ngl 99 -c 16384 --temp 0.1 --mlock --reasoning off > "$LOG_DIR/llama_server.log" 2>&1 &
|
||||
LLM_BIN="/Users/accusys/momentry_resources/llama/bin/llama-server"
|
||||
LLM_MODEL="/Users/accusys/momentry/models/llm/google_gemma-4-26B-A4B-it-Q5_K_M.gguf"
|
||||
"$LLM_BIN" -m "$LLM_MODEL" --host 0.0.0.0 --port 8082 -ngl 99 -c 16384 --temp 0.1 --mlock --reasoning off > "$LOG_DIR/llama_server.log" 2>&1 &
|
||||
echo -e " ${YELLOW}⏳ loading model (~30s)...${NC}"
|
||||
for i in $(seq 1 30); do
|
||||
sleep 2
|
||||
@@ -96,8 +97,27 @@ else
|
||||
curl -s -o /dev/null -w "%{http_code}" --connect-timeout 3 http://localhost:8082/health 2>/dev/null | grep -q 200; check "started"
|
||||
fi
|
||||
|
||||
# ── 6. Embedding Server ──
|
||||
echo -e "${YELLOW}[6/7] EmbeddingGemma${NC}"
|
||||
# ── 6. MariaDB ──
|
||||
echo -e "${YELLOW}[6/9] MariaDB${NC}"
|
||||
MARIADB_BIN="/Users/accusys/momentry_resources/mariadb/bin/mariadbd"
|
||||
MARIADB_DATA="/Users/accusys/momentry/var/mysql"
|
||||
if [ -S /tmp/mysql.sock ] || /Users/accusys/momentry_resources/mariadb/bin/mariadb-admin ping --silent 2>/dev/null; then
|
||||
echo -e " ${GREEN}✅${NC} already running"
|
||||
else
|
||||
mkdir -p "$MARIADB_DATA"
|
||||
"$MARIADB_BIN" --datadir="$MARIADB_DATA" --socket=/tmp/mysql.sock --port=3306 \
|
||||
> "$LOG_DIR/mariadb.log" 2>&1 &
|
||||
for i in $(seq 1 10); do
|
||||
sleep 2
|
||||
if /Users/accusys/momentry_resources/mariadb/bin/mariadb-admin ping --silent 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
/Users/accusys/momentry_resources/mariadb/bin/mariadb-admin ping --silent 2>/dev/null; check "started"
|
||||
fi
|
||||
|
||||
# ── 7. Embedding Server ──
|
||||
echo -e "${YELLOW}[7/9] EmbeddingGemma${NC}"
|
||||
if curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 http://localhost:11436/health 2>/dev/null | grep -q 200; then
|
||||
echo -e " ${GREEN}✅${NC} already running"
|
||||
else
|
||||
@@ -107,22 +127,34 @@ else
|
||||
VENV_PYTHON="/opt/homebrew/bin/python3.11"
|
||||
pip install flask 2>/dev/null || true
|
||||
fi
|
||||
nohup "$VENV_PYTHON" "$EMBED_SCRIPT" --port 11436 > "$LOG_DIR/embed.log" 2>&1 &
|
||||
"$VENV_PYTHON" "$EMBED_SCRIPT" --port 11436 > "$LOG_DIR/embed.log" 2>&1 &
|
||||
sleep 5
|
||||
curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 http://localhost:11436/health 2>/dev/null | grep -q 200; check "started"
|
||||
fi
|
||||
|
||||
# ── 7. Playground Server ──
|
||||
echo -e "${YELLOW}[7/7] Playground API Server${NC}"
|
||||
# ── 8. Playground Server ──
|
||||
echo -e "${YELLOW}[8/9] Playground API Server${NC}"
|
||||
if curl -s -o /dev/null -w "%{http_code}" -H "X-API-Key: muser_68600856036340bcafc01930eb4bd839_1774418104_97221b69" --connect-timeout 5 http://127.0.0.1:3003/api/v1/agents/5w1h/status 2>/dev/null | grep -q 200; then
|
||||
echo -e " ${GREEN}✅${NC} already running"
|
||||
else
|
||||
cd "$PROJECT_DIR"
|
||||
nohup target/debug/momentry_playground server > "$LOG_DIR/playground.log" 2>&1 &
|
||||
target/debug/momentry_playground server > "$LOG_DIR/playground.log" 2>&1 &
|
||||
sleep 4
|
||||
curl -s -o /dev/null -w "%{http_code}" -H "X-API-Key: muser_68600856036340bcafc01930eb4bd839_1774418104_97221b69" --connect-timeout 5 http://127.0.0.1:3003/api/v1/agents/5w1h/status 2>/dev/null | grep -q 200; check "started"
|
||||
fi
|
||||
|
||||
# ── 9. Caddy ──
|
||||
echo -e "${YELLOW}[9/9] Caddy${NC}"
|
||||
CADDY_BIN="/Users/accusys/momentry_resources/bin/caddy"
|
||||
CADDY_CONFIG="/Users/accusys/momentry/etc/Caddyfile"
|
||||
if curl -s -o /dev/null -w "%{http_code}" --connect-timeout 3 http://127.0.0.1:2019/config/ 2>/dev/null | grep -q 200; then
|
||||
echo -e " ${GREEN}✅${NC} already running"
|
||||
else
|
||||
"$CADDY_BIN" run --config "$CADDY_CONFIG" > "$LOG_DIR/caddy.log" 2>&1 &
|
||||
sleep 3
|
||||
curl -s -o /dev/null -w "%{http_code}" --connect-timeout 3 http://127.0.0.1:2019/config/ 2>/dev/null | grep -q 200; check "started"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
if [ ${#FAILURES[@]} -eq 0 ]; then
|
||||
echo -e "${GREEN}====================================${NC}"
|
||||
@@ -136,9 +168,12 @@ else
|
||||
fi
|
||||
echo ""
|
||||
echo " Playground: http://127.0.0.1:3003"
|
||||
echo " Caddy: http://127.0.0.1:2019"
|
||||
echo " WordPress: http://m5max128wp.momentry.ddns.net:8081"
|
||||
echo " LLM: http://127.0.0.1:8082"
|
||||
echo " Embedding: http://127.0.0.1:11436"
|
||||
echo " Qdrant: http://localhost:6333"
|
||||
echo " PostgreSQL: localhost:5432"
|
||||
echo " Redis: localhost:6379"
|
||||
echo " MariaDB: localhost:3306"
|
||||
echo ""
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use axum::Router;
|
||||
use tokio::time::timeout;
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
|
||||
use crate::core::cache::{MongoCache, RedisCache};
|
||||
@@ -30,7 +33,21 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
|
||||
health::init_server_state(host, port);
|
||||
|
||||
let embedder = std::sync::Arc::new(Embedder::new("nomic-embed-text-v2-moe:latest".to_string()));
|
||||
let mongo_cache = MongoCache::init().await?;
|
||||
|
||||
// MongoDB is ONLY a cache layer — if unavailable, the server continues
|
||||
// with Redis cache alone. This keeps both 3002 and 3003 bootable
|
||||
// without requiring MongoDB to be installed or running.
|
||||
let mongo_cache = match timeout(Duration::from_secs(5), MongoCache::init()).await {
|
||||
Ok(Ok(cache)) => cache,
|
||||
Ok(Err(e)) => {
|
||||
tracing::warn!("MongoDB cache unavailable (continuing without): {e}");
|
||||
MongoCache::disabled().await
|
||||
}
|
||||
Err(_) => {
|
||||
tracing::warn!("MongoDB init timed out (continuing without cache)");
|
||||
MongoCache::disabled().await
|
||||
}
|
||||
};
|
||||
let redis_cache = RedisCache::new()?;
|
||||
let db = PostgresDb::init().await?;
|
||||
|
||||
|
||||
19
src/core/cache/mongo_cache.rs
vendored
19
src/core/cache/mongo_cache.rs
vendored
@@ -80,6 +80,25 @@ impl MongoCache {
|
||||
Ok(cache)
|
||||
}
|
||||
|
||||
/// Create a disabled cache instance — all ops are no-ops (is_enabled() = false).
|
||||
/// Used when MongoDB is unavailable; Redis cache continues independently.
|
||||
pub async fn disabled() -> Self {
|
||||
let client = Client::with_uri_str("mongodb://localhost:27017")
|
||||
.await
|
||||
.expect("disabled mongo client (lazy — no actual connect)");
|
||||
let db = client.database("disabled_cache");
|
||||
Self {
|
||||
client,
|
||||
db: db.clone(),
|
||||
collection: db.collection("disabled"),
|
||||
settings: CacheSettings {
|
||||
enabled: false,
|
||||
..Default::default()
|
||||
},
|
||||
initialized: Arc::new(RwLock::new(false)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn ensure_indexes(&self) -> Result<()> {
|
||||
let mut guard = self.initialized.write().await;
|
||||
if *guard {
|
||||
|
||||
Reference in New Issue
Block a user