Files
server/my_deepseek.sh

68 lines
2.4 KiB
Bash
Raw Permalink 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.
#!/bin/bash
# my_deepseek - 一键启动 DeepSeek Harness Web UI + socat 桥接
#
# 用法:
# my_deepseek [工作目录] # 启动 dsh,默认工作目录=当前目录
# my_deepseek stop # 停止 dsh 和 socat
#
# 说明:
# - dsh Web UI 监听 127.0.0.1:DSH_PORT(官方禁止 --host 0.0.0.0
# - socat 桥接 EXT_PORT -> DSH_PORT,供外部经 Xray 隧道访问
# - socat 带 retrydsh 未就绪时每 1 秒重试,直到连上
# - 防重复:启动前检查端口占用,已运行则直接提示
# - 清理:stop 子命令或 Ctrl+C 时杀掉 socat,不留僵尸
DSH_PORT=37999
EXT_PORT=3080
TRUST_HOSTS="--trusted-host 49.232.242.90 --trusted-host salmonstill.cn --trusted-host opencode.salmonstill.cn --trusted-host ai.salmonstill.cn --trusted-host 192.168.1.166"
stop_all() {
pkill -f "dsh web" 2>/dev/null
pkill -f "socat.*TCP-LISTEN:${EXT_PORT}" 2>/dev/null
echo "[my_deepseek] 已停止 dsh 与 socat"
}
case "${1}" in
stop)
stop_all
exit 0
;;
-h|--help|help)
grep '^#' "$0" | sed 's/^# \{0,1\}//'
exit 0
;;
esac
# 防重复:dsh 端口已被占用则直接退出
if ss -tln | grep -q ":${DSH_PORT} "; then
echo "[my_deepseek] dsh 已在运行,访问 http://49.232.242.90:${EXT_PORT}"
exit 0
fi
# EXT_PORT 被其他程序占用则明确报错(如 opencode 占用 38662
if ss -tln | grep -q ":${EXT_PORT} "; then
echo "[my_deepseek] 错误: 端口 ${EXT_PORT} 已被占用:"
ss -tlnp | grep ":${EXT_PORT} "
echo "请先释放该端口(例如 tmux kill-session -t opencode)再启动"
exit 1
fi
# 清理可能残留的 socat
pkill -f "socat.*TCP-LISTEN:${EXT_PORT}" 2>/dev/null
sleep 0.3
# 应用 403 修复补丁(幂等,见 dsh-local-403-fix/apply-403-fix.sh
FIX_DIR="$(cd "$(dirname "$0")/dsh-local-403-fix" && pwd)"
if ! "$FIX_DIR/apply-403-fix.sh"; then
echo "[my_deepseek] 错误: 403 修复补丁应用失败,拒绝启动(详见 dsh-local-403-fix/apply-403-fix.sh"
exit 1
fi
# 后台启动 socat(带 retry,dsh 未就绪时自动重试连接)
nohup socat TCP-LISTEN:${EXT_PORT},fork,reuseaddr,retry,interval=1 TCP:127.0.0.1:${DSH_PORT} >/tmp/my_deepseek-socat.log 2>&1 &
disown
# 前台启动 dshCtrl+C 退出 dsh,可用 my_deepseek stop 清理 socat
cd "${1:-$(pwd)}" || exit 1
exec dsh web --port ${DSH_PORT} ${TRUST_HOSTS}