Files
crypto_monitor/manual_trading_hub/scripts/pm2_hub.sh
T

70 lines
1.5 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
# 中控 PM2 快捷脚本(在 manual_trading_hub 目录或任意路径执行均可)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HUB_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
ECO="${HUB_DIR}/ecosystem.config.cjs"
usage() {
cat <<'EOF'
用法: bash scripts/pm2_hub.sh <start|stop|restart|status|logs|delete>
start 启动 manual-trading-hub(已存在则 pm2 restart
stop 停止
restart 重启
status pm2 status
logs 跟踪日志(Ctrl+C 退出)
delete 从 PM2 列表移除
前置: npm i -g pm2manual_trading_hub 下已建 .venv 并 pip install
可选: cp .env.example .env
EOF
}
cmd="${1:-}"
if ! command -v pm2 >/dev/null 2>&1; then
echo "未找到 pm2,请先: npm install -g pm2" >&2
exit 1
fi
if [[ ! -f "${ECO}" ]]; then
echo "未找到 ${ECO}" >&2
exit 1
fi
cd "${HUB_DIR}"
case "${cmd}" in
start)
if pm2 describe manual-trading-hub >/dev/null 2>&1; then
pm2 restart manual-trading-hub
echo "已重启 manual-trading-hub"
else
pm2 start "${ECO}"
echo "已启动 manual-trading-hub"
fi
pm2 save 2>/dev/null || true
;;
stop)
pm2 stop manual-trading-hub 2>/dev/null || echo "进程未在运行"
;;
restart)
pm2 restart manual-trading-hub 2>/dev/null || pm2 start "${ECO}"
;;
status)
pm2 status
;;
logs)
pm2 logs manual-trading-hub --lines 200
;;
delete)
pm2 delete manual-trading-hub 2>/dev/null || echo "进程不存在"
;;
*)
usage
exit 1
;;
esac