Files
qihuo/deploy.sh
T
dekun f73d436077 fix: CTP 连接后 locale 崩溃,PM2 设置 LANG=C.UTF-8
vnpy_ctp C++ 扩展在缺 locale 时会 terminate;补充 SimNow 备用前置说明。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:32:20 +08:00

94 lines
2.6 KiB
Bash
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
# 国内期货监控系统 - Ubuntu 一键部署
# root 用户 | 目录 /opt/qihuo | 端口 6600 | PM2
set -euo pipefail
APP_DIR="/opt/qihuo"
REPO_URL="https://git.bz121.com/dekun/qihuo.git"
SERVICE_NAME="qihuo"
if [ "$(id -u)" -ne 0 ]; then
echo "请使用 root 用户运行: sudo bash deploy.sh"
exit 1
fi
echo "==> 检查系统依赖..."
apt-get update -qq
need_install() {
if ! command -v "$1" &>/dev/null; then
apt-get install -y "$2"
fi
}
need_install python3 python3
need_install python3-venv python3-venv
need_install git git
# vnpy_ctp 在 Linux 上需本地编译(Meson + pkg-config 查找 python3-dev
echo "==> 安装 vnpy_ctp 编译依赖..."
apt-get install -y build-essential python3-dev pkg-config locales
locale-gen en_US.UTF-8 2>/dev/null || true
update-locale LANG=C.UTF-8 LC_ALL=C.UTF-8 2>/dev/null || true
if ! command -v pm2 &>/dev/null; then
echo "==> 安装 PM2..."
if ! command -v npm &>/dev/null; then
need_install nodejs nodejs
need_install npm npm
fi
npm install -g pm2
fi
echo "==> 准备应用目录 ${APP_DIR}..."
mkdir -p "$(dirname "$APP_DIR")"
if [ -d "$APP_DIR/.git" ]; then
echo "==> 更新已有仓库..."
cd "$APP_DIR"
git pull origin main || git pull origin master || true
else
if [ -d "$APP_DIR" ] && [ "$(ls -A "$APP_DIR" 2>/dev/null)" ]; then
echo "目录 ${APP_DIR} 已存在且非 git 仓库,请手动处理后重试"
exit 1
fi
git clone "$REPO_URL" "$APP_DIR"
cd "$APP_DIR"
fi
echo "==> Python 虚拟环境与依赖..."
if [ ! -d "$APP_DIR/venv" ]; then
python3 -m venv "$APP_DIR/venv"
fi
source "$APP_DIR/venv/bin/activate"
pip install --upgrade pip -q
pip install -r "$APP_DIR/requirements.txt"
python -c "from vnpy_ctp import CtpGateway; print('vnpy_ctp OK')"
if [ ! -f "$APP_DIR/.env" ]; then
echo "==> 生成 .env(请编辑 ADMIN_PASSWORD 后重启)..."
cp "$APP_DIR/.env.example" "$APP_DIR/.env"
RAND_KEY=$(python3 -c "import secrets; print(secrets.token_hex(32))")
sed -i "s/change-this-to-a-random-secret-key/${RAND_KEY}/" "$APP_DIR/.env"
fi
mkdir -p "$APP_DIR/logs"
echo "==> PM2 启动/重启服务..."
cd "$APP_DIR"
pm2 delete "$SERVICE_NAME" 2>/dev/null || true
pm2 start ecosystem.config.cjs
pm2 save
echo ""
echo "=========================================="
echo " 部署完成"
echo " 目录: ${APP_DIR}"
echo " 用户: root"
echo " 端口: 6600"
echo " 访问: http://<服务器IP>:6600"
echo " 日志: pm2 logs ${SERVICE_NAME}"
echo " 开机自启: pm2 startup && pm2 save"
echo "=========================================="