首次上传

This commit is contained in:
dekun
2026-05-16 22:25:48 +08:00
commit 2b8f902548
88 changed files with 16386 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
# deploy 脚本说明
所有脚本默认项目路径为 **`/root/gate_order_executor`**;可通过第一个参数传入你的绝对路径(`bootstrap.sh``start.sh`)。
| 文件 | 作用 |
|------|------|
| `ecosystem.config.cjs` | PM2 配置:单实例、`PYTHONUNBUFFERED=1`、日志在 `runtime/` |
| `bootstrap.sh` | 首次:`venv` + `pip install -r requirements.txt` + 生成 `config.yaml` 模板 |
| `start.sh` | 前台运行 `python run.py`(调试用) |
| `pm2-start.sh` | PM2 启动;若应用已存在则 `restart` |
| `pm2-restart.sh` | `pm2 restart gate-order-executor` |
| `pm2-stop.sh` | `pm2 stop gate-order-executor` |
| `pm2-delete.sh` | `pm2 delete gate-order-executor` |
| `gate-order-executor.service` | systemd 示例(需改 `WorkingDirectory``pm2-runtime` 路径) |
使用说明与接口文档:`../docs/使用说明.md`
部署步骤:`../docs/部署说明.md`
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# 首次部署:创建 venv、安装依赖、生成 config 模板、创建 runtime 目录。
# 用法:bash deploy/bootstrap.sh [项目绝对路径]
# 默认:/root/gate_order_executor
set -euo pipefail
PROJECT_DIR="${1:-/root/gate_order_executor}"
cd "$PROJECT_DIR"
if ! command -v python3 >/dev/null 2>&1; then
echo "请先安装 python3" >&2
exit 1
fi
python3 -m venv .venv
# shellcheck source=/dev/null
source .venv/bin/activate
python -m pip install -U pip
python -m pip install -r requirements.txt
# SOCKS 代理与扫描一致时建议安装(与 httpx[socks] 一致)
python -m pip install "socksio>=1.0,<2" || true
if [ ! -f config.yaml ]; then
cp -n config.example.yaml config.yaml
echo "已从 config.example.yaml 创建 config.yaml,请编辑:auth、security.webhook_secret、proxy、gate 等。"
fi
mkdir -p runtime
echo "Bootstrap 完成:$PROJECT_DIR"
@@ -0,0 +1,38 @@
/**
* PM2 守护 gate_order_executorGate 下单执行器)
*
* 在项目根目录执行:
* ./deploy/pm2-start.sh
* 或:
* pm2 start deploy/ecosystem.config.cjs
*
* 监听 host/port 来自项目根目录 config.yaml → app.host / app.port(由 run.py 内 uvicorn 读取)。
*/
const path = require("path");
const ROOT = path.resolve(__dirname, "..");
const isWin = process.platform === "win32";
const py = path.join(ROOT, isWin ? path.join(".venv", "Scripts", "python.exe") : path.join(".venv", "bin", "python"));
module.exports = {
apps: [
{
name: "gate-order-executor",
cwd: ROOT,
script: py,
args: ["run.py"],
interpreter: "none",
autorestart: true,
watch: false,
max_restarts: 20,
min_uptime: "10s",
exp_backoff_restart_delay: 2000,
error_file: path.join(ROOT, "runtime", "pm2-executor-error.log"),
out_file: path.join(ROOT, "runtime", "pm2-executor-out.log"),
merge_logs: true,
time: true,
env: {
PYTHONUNBUFFERED: "1",
},
},
],
};
@@ -0,0 +1,18 @@
[Unit]
Description=Gate Order Executor (Python) via PM2
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/root/gate_order_executor
Environment=NODE_ENV=production
Environment=PYTHONUNBUFFERED=1
# 需全局安装:npm install -g pm2
# 若 pm2-runtime 不在 PATH,请改为绝对路径:which pm2-runtime
ExecStart=/usr/bin/pm2-runtime start deploy/ecosystem.config.cjs
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
if ! command -v pm2 >/dev/null 2>&1; then
echo "未找到 pm2" >&2
exit 1
fi
pm2 delete gate-order-executor || true
pm2 save || true
echo "已从 PM2 删除 gate-order-executor"
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
if ! command -v pm2 >/dev/null 2>&1; then
echo "未找到 pm2" >&2
exit 1
fi
pm2 restart gate-order-executor --update-env
echo "已重启 gate-order-executor"
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# 使用 PM2 启动 gate-order-executor(需已 bootstrap 且已配置 config.yaml
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
if ! command -v pm2 >/dev/null 2>&1; then
echo "未找到 pm2,请先执行:npm install -g pm2" >&2
exit 1
fi
if [ ! -x ".venv/bin/python" ]; then
echo "未找到 .venv/bin/python,请先执行:bash deploy/bootstrap.sh \"$ROOT\"" >&2
exit 1
fi
mkdir -p runtime
if pm2 describe gate-order-executor >/dev/null 2>&1; then
echo "进程已存在,改为重启:pm2 restart gate-order-executor"
pm2 restart gate-order-executor --update-env
else
pm2 start "$ROOT/deploy/ecosystem.config.cjs"
fi
pm2 save || true
echo "已启动。日志:pm2 logs gate-order-executor"
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
if ! command -v pm2 >/dev/null 2>&1; then
echo "未找到 pm2" >&2
exit 1
fi
pm2 stop gate-order-executor || true
echo "已停止 gate-order-executor(进程仍在列表中可用 pm2 delete 删除)"
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# 前台调试(无 PM2)。生产请用:./deploy/pm2-start.sh
# 用法:bash deploy/start.sh [项目绝对路径]
set -euo pipefail
PROJECT_DIR="${1:-/root/gate_order_executor}"
cd "$PROJECT_DIR"
# shellcheck source=/dev/null
source .venv/bin/activate
exec python run.py