59 lines
2.1 KiB
Bash
Executable File
59 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
set -e
|
||
WORKDIR="$(cd "$(dirname "$0")" && pwd)"
|
||
cd "$WORKDIR"
|
||
|
||
# 加载本机敏感环境变量(如短信密钥),不存在则跳过(该文件不入库)
|
||
[ -f .smssend ] && source .smssend
|
||
# 加载本机部署环境(如 BASEURL:生成物/媒体文件的公网回源地址前缀),不入库
|
||
[ -f .pipelineenv ] && source .pipelineenv
|
||
|
||
# 运行模式:all(默认,HTTP+poller) / web(仅HTTP,无poller) / worker(仅poller,分布式worker节点)
|
||
# 多 worker 本机/跨机测试:bash start.sh worker <id>(id=1,2,3...,端口 9090+id,pid 独立)
|
||
MODE="${1:-all}"
|
||
case "$MODE" in
|
||
web) PORT=9090; PIDFILE="pipeline-web.pid"; PIPELINE_MODE=web ;;
|
||
worker)
|
||
WID="${2:-1}"
|
||
PORT=$((9090 + WID))
|
||
PIDFILE="pipeline-worker-${WID}.pid"
|
||
PIPELINE_MODE=worker ;;
|
||
all) PORT=9090; PIDFILE="pipeline.pid"; PIPELINE_MODE=all ;;
|
||
*) echo "用法: $0 [web|worker <id>|all]"; exit 1 ;;
|
||
esac
|
||
export PIPELINE_MODE
|
||
|
||
if [ -f "$PIDFILE" ]; then
|
||
pid=$(cat "$PIDFILE")
|
||
if kill -0 "$pid" 2>/dev/null; then
|
||
echo "Already running (PID $pid)"
|
||
exit 0
|
||
fi
|
||
rm -f "$PIDFILE"
|
||
fi
|
||
|
||
echo "Starting pipeline-app ($MODE mode) on port $PORT..."
|
||
export PATH="$WORKDIR/bin:$PATH"
|
||
$WORKDIR/py3/bin/python $WORKDIR/app/pipeline_app.py -p $PORT -w $WORKDIR >> $WORKDIR/logs/pipeline.log 2>&1 &
|
||
echo $! > "$PIDFILE"
|
||
echo "Started PID $(cat $PIDFILE)"
|
||
|
||
# 独立异步记账进程(模型用量出账:客户付/商户营收/供应商成本)
|
||
# 只随主进程/worker 启动;web 单独模式不启动(同步记账在 web 内)
|
||
if [ "$MODE" != "web" ]; then
|
||
ACC_PIDFILE="pipeline-accounting.pid"
|
||
if [ -f "$ACC_PIDFILE" ]; then
|
||
acc_pid=$(cat "$ACC_PIDFILE")
|
||
if kill -0 "$acc_pid" 2>/dev/null; then
|
||
echo "Accounting worker already running (PID $acc_pid)"
|
||
else
|
||
rm -f "$ACC_PIDFILE"
|
||
fi
|
||
fi
|
||
if [ ! -f "$ACC_PIDFILE" ]; then
|
||
$WORKDIR/py3/bin/python $WORKDIR/app/pipeline_accounting_worker.py -w $WORKDIR >> $WORKDIR/logs/pipeline-accounting.log 2>&1 &
|
||
echo $! > "$ACC_PIDFILE"
|
||
echo "Started accounting worker PID $(cat $ACC_PIDFILE)"
|
||
fi
|
||
fi
|