Files
huike-back/scripts/moicen_start_huiwings_stack.sh
T
weli 0e53c9f66d feat(htykc): clazz completed_at migration; logrotate for htykc/htyproc/htyts
Portable run_rotate; moicen_start_huiwings_stack and ws_clazz updates; schema/models sync.

Made-with: Cursor
2026-04-26 17:14:44 +08:00

63 lines
3.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 在**新** moicen 裸机:与旧机 alchemy 相同布局(/mnt/.../AuthCore + huike-back),
# 在已「cp_envs + pg *_huiwings 数据 + redis 已起 + 已 cargo build --release 可选」后,nohup 起 UC/WS/KC(与现网进程方式一致:在各 crate 子目录 cargo run 以读 .env)。
# 日志轮转:见仓库 `huike-back/run_rotate.sh` 与 `plan_skills/moicen/moicen-cutover-config-worklog-2026-04-26.md` §8.1(新机 weli crontab 每 5 分钟)。
# 在 huike-back 根以: ./scripts/moicen_start_huiwings_stack.sh
# 可设 MOICEN_HUIKE_ROOT / MOICEN_AUTH_ROOT 为绝对路径(默认=本脚本的 ../ 与 ../AuthCore)。
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HUIKE_DEFAULT="$(cd "$SCRIPT_DIR/.." && pwd)"
# scripts/.. = huike-back, ../.. = monorepo 根
REPO_ROOT_DEFAULT="$(cd "$SCRIPT_DIR/../.." && pwd)"
AUTH_DEFAULT="$REPO_ROOT_DEFAULT/AuthCore"
HUIKE="${MOICEN_HUIKE_ROOT:-$HUIKE_DEFAULT}"
if [ -d "$AUTH_DEFAULT/htyuc" ]; then
AUTH="${MOICEN_AUTH_ROOT:-$AUTH_DEFAULT}"
else
AUTH="${MOICEN_AUTH_ROOT:-$(cd "$HUIKE/../AuthCore" 2>/dev/null && pwd || true)}"
fi
[ -d "$HUIKE/htyws" ] && [ -d "$AUTH/htyuc" ] || { echo "需要 monorepo\$HUIKE= $HUIKE 、\$AUTH= $AUTH"; exit 1; }
# 默认不覆盖 .env;要铺 envs 时显式设其一:MOICEN_ENV_COPY=huiwings | moicen
if [ "${MOICEN_ENV_COPY:-}" = huiwings ] && [ -x "$HUIKE/cp_envs_moicen_huiwings_databases.sh" ]; then
"$HUIKE/cp_envs_moicen_huiwings_databases.sh"
elif [ "${MOICEN_ENV_COPY:-}" = moicen ] && [ -x "$HUIKE/cp_envs_moicen.sh" ]; then
( cd "$HUIKE" && sh ./cp_envs_moicen.sh )
for _f in htyuc htyuc_models; do
if [ -d "$AUTH/$_f" ] && [ -f "$HUIKE/envs/moicen/htyuc.env" ]; then
cp "$HUIKE/envs/moicen/htyuc.env" "$AUTH/$_f/.env"
fi
done
fi
if ! command -v redis-cli >/dev/null 2>&1 || ! redis-cli -h 127.0.0.1 -p 6379 ping 2>/dev/null | grep -q PONG; then
echo "Redis 未响应 127.0.0.1:6379,请先启动 redis。" >&2
exit 1
fi
REL=""
# 有任一 release 可执行则全程加 --release(与旧机用 debug 时可改 REL 或先不 build --release
if [ -f "$AUTH/target/release/htyuc" ] 2>/dev/null || [ -f "$HUIKE/target/release/htyws" ] 2>/dev/null; then
REL=--release
fi
# 出网时若设过 ALL_PROXY 用于 cargo 下载,**启动 HTTP 时勿继承**(本服务连本机 PG/Redis,走 SOCKS 会异常或慢)
CARGO_NO_PROXY=(env -u ALL_PROXY -u all_proxy -u http_proxy -u https_proxy -u HTTP_PROXY -u HTTPS_PROXY)
# shellcheck disable=SC1090
_SRC_ENV='[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"'
# AuthCore: CWD=htyuc 与现网 htyuc 进程一致
( cd "$AUTH/htyuc" && nohup "${CARGO_NO_PROXY[@]}" bash -c "$_SRC_ENV; exec cargo run $REL" >>"$AUTH/htyuc/htyuc.nohup.log" 2>&1 ) &
( cd "$HUIKE/htyws" && nohup "${CARGO_NO_PROXY[@]}" bash -c "$_SRC_ENV; exec cargo run $REL" >>"$HUIKE/htyws/htyws.nohup.log" 2>&1 ) &
( cd "$HUIKE/htykc" && nohup "${CARGO_NO_PROXY[@]}" bash -c "$_SRC_ENV; exec cargo run $REL" >>"$HUIKE/htykc/htykc.nohup.log" 2>&1 ) &
if [ -d "$HUIKE/htyts" ] && { [ "${MOICEN_START_HTYTS:-0}" = 1 ] || [ "${MOICEN_START_HTYTS:-0}" = yes ]; }; then
( cd "$HUIKE/htyts" && nohup "${CARGO_NO_PROXY[@]}" bash -c "$_SRC_ENV; exec cargo run $REL" >>"$HUIKE/htyts/htyts.nohup.log" 2>&1 ) &
fi
echo "已后台启动。日志: $AUTH/htyuc/htyuc.nohup.log, $HUIKE/htyws/htyws.nohup.log, $HUIKE/htykc/htykc.nohup.log"
echo "htyts 需另设 export MOICEN_START_HTYTS=1 再执行本脚本。"