feat/add_search #1

Merged
daniel.w merged 8 commits from feat/add_search into main 2026-06-29 16:11:12 +00:00
3 changed files with 85 additions and 0 deletions
Showing only changes of commit ae89e0451e - Show all commits

59
start-prod.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
set -e
echo "=== 巡樓 Production 啟動 ==="
# 1. 確認 nginx 不會被 default site 搶走
echo "[1/7] 確保 nginx config..."
if [ -f /etc/nginx/sites-enabled/default ]; then
sudo rm /etc/nginx/sites-enabled/default
fi
# 2. 起 infra (Mongo + Redis)
echo "[2/7] 啟動 Mongo + Redis..."
docker compose -f infra/docker-compose.yml --env-file infra/.env up -d
# 3. 確保 Playwright 瀏覽器已安裝
echo "[3/7] 確認 Playwright chromium..."
if [ ! -d /opt/haixun/.cache/ms-playwright/chromium-1228 ]; then
sudo -u haixun bash -c 'cd /opt/haixun/node-worker && npx playwright install chromium'
fi
# 4. 清除 systemd 失敗計數(之前 crash loop 的話需要 reset
echo "[4/7] 重置 systemd 狀態..."
for svc in haixun-gateway haixun-worker haixun-node-worker; do
sudo systemctl reset-failed "$svc" 2>/dev/null || true
done
# 5. 啟動 systemd 服務
echo "[5/7] 啟動 backend gateway..."
sudo systemctl start haixun-gateway
echo "[5/7] 啟動 worker..."
sudo systemctl start haixun-worker
echo "[5/7] 啟動 node worker..."
sudo systemctl start haixun-node-worker
# 6. 初始化 DBindexes + admin冪等
echo "[6/7] 初始化 DBadmin: admin@30cm.net..."
set -a; source /opt/haixun/etc/haixun.env; set +a
sudo -E /opt/haixun/bin/tool init -f /opt/haixun/etc/gateway.prod.yaml
# 7. 確認 nginx 執行 + reload config
echo "[7/7] 確認 nginx..."
sudo nginx -t && sudo systemctl start nginx && sudo systemctl reload nginx
echo ""
echo "=== 啟動完成 ==="
echo " nginx: $(systemctl is-active nginx)"
echo " gateway: $(systemctl is-active haixun-gateway)"
echo " worker: $(systemctl is-active haixun-worker)"
echo " node-wkr: $(systemctl is-active haixun-node-worker)"
echo " docker: $(docker compose -f infra/docker-compose.yml ps --status running 2>/dev/null | wc -l) containers running"
echo ""
echo "健康檢查:"
echo " curl http://localhost/api/v1/health"
echo ""
echo "查看日誌:"
echo " journalctl -u haixun-gateway -n 50 --no-pager -f"
echo " journalctl -u haixun-worker -n 50 --no-pager -f"
echo " docker compose -f infra/docker-compose.yml logs -f"

20
status-prod.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
echo "=== 巡樓 Production 狀態 ==="
echo ""
echo "--- Nginx ---"
systemctl status nginx --no-pager -n 5 2>&1 | head -5
echo ""
echo "--- Gateway ---"
systemctl status haixun-gateway --no-pager -n 5 2>&1 | head -5
echo ""
echo "--- Worker ---"
systemctl status haixun-worker --no-pager -n 5 2>&1 | head -5
echo ""
echo "--- Node Worker ---"
systemctl status haixun-node-worker --no-pager -n 5 2>&1 | head -5
echo ""
echo "--- Docker Infra ---"
docker compose -f /home/daniel/thread-master/infra/docker-compose.yml ps 2>&1
echo ""
echo "--- Port 8890 ---"
ss -tlnp | grep 8890 || echo "gateway not listening"

6
stop-prod.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
echo "=== 巡樓 Production 停止 ==="
sudo systemctl stop haixun-worker
sudo systemctl stop haixun-gateway
docker compose -f /home/daniel/thread-master/infra/docker-compose.yml down
echo "done"