Files
memind/scripts/run-memind-portal-prod.sh
john df5bcd87b5
Memind CI / Test, build, and release guards (pull_request) Failing after 18s
fix: route stable production goosed through DeepSeek no-think proxy
DeepSeek V4 tool rounds fail with reasoning_content errors when stable
goosed hits api.deepseek.com directly. Default stable portal startup to
the 18036 compat proxy and add a standalone recovery script for 103 ops.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-30 10:43:26 +08:00

63 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
if [[ -f "${ROOT}/.env" ]]; then
set -a
# shellcheck disable=SC1091
source "${ROOT}/.env"
set +a
fi
export NODE_ENV=production
export H5_PORT="${H5_PORT:-8081}"
export H5_PUBLIC_BASE_URL="${H5_PUBLIC_BASE_URL:-https://m.tkmind.cn}"
export TKMIND_API_TARGETS="${TKMIND_API_TARGETS:-https://127.0.0.1:18006,https://127.0.0.1:18007,https://127.0.0.1:18008,https://127.0.0.1:18009,https://127.0.0.1:18010,https://127.0.0.1:18011,https://127.0.0.1:18012,https://127.0.0.1:18013,https://127.0.0.1:18014}"
export TKMIND_API_TARGET="${TKMIND_API_TARGET:-https://127.0.0.1:18006}"
export TKMIND_API_TARGET_1="${TKMIND_API_TARGET_1:-https://127.0.0.1:18007}"
NODE_BIN="${NODE_BIN:-/opt/homebrew/opt/node@24/bin/node}"
if [[ ! -x "${NODE_BIN}" ]]; then
NODE_BIN="$(command -v node)"
fi
export GOOSED_MCP_NODE_PATH="${GOOSED_MCP_NODE_PATH:-${NODE_BIN}}"
export GOOSED_MCP_SERVER_PATH="${GOOSED_MCP_SERVER_PATH:-${ROOT}/mindspace-sandbox-mcp.mjs}"
# DeepSeek V4 tool rounds require reasoning_content replay; stable goosed must use the
# host no-think compat proxy (see docs/发包必看.md §4.7).
export MEMIND_DEEPSEEK_DISABLE_THINKING="${MEMIND_DEEPSEEK_DISABLE_THINKING:-1}"
export MEMIND_DEEPSEEK_NO_THINK_PORT="${MEMIND_DEEPSEEK_NO_THINK_PORT:-18036}"
export MEMIND_GOOSED_HOST_GATEWAY="${MEMIND_GOOSED_HOST_GATEWAY:-host.docker.internal}"
free_port_if_stale_memind_listener() {
local port="${H5_PORT:-8081}"
local pids
pids="$(lsof -tiTCP:"${port}" -sTCP:LISTEN 2>/dev/null || true)"
[[ -z "${pids}" ]] && return 0
while read -r pid; do
[[ -z "${pid}" ]] && continue
local args
args="$(ps -p "${pid}" -o args= 2>/dev/null || true)"
if [[ "${args}" == *"${ROOT}/server.mjs"* ]]; then
echo "[portal-start] stopping stale Memind listener pid=${pid}" >&2
kill "${pid}" 2>/dev/null || true
sleep 1
if kill -0 "${pid}" 2>/dev/null; then
kill -9 "${pid}" 2>/dev/null || true
sleep 1
fi
continue
fi
echo "[portal-start] port ${port} held by foreign pid=${pid}; refusing to start" >&2
exit 1
done <<< "${pids}"
}
free_port_if_stale_memind_listener
exec "${NODE_BIN}" "${ROOT}/server.mjs"