Files
soul-yongping/soul-api/deploy/runner/entrypoint.sh
Alex-larget 6df1736e1e 1
2026-03-20 14:47:37 +08:00

37 lines
1.2 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.

#!/bin/sh
# soul-api Runner 容器入口
# 启动 Redis、Nginx首次部署时需外部调用 deploy.sh
set -e
APP_ROOT="/app"
REDIS_PASS="soul-docker-redis"
# 启动 Redis后台
if ! pgrep -x redis-server >/dev/null 2>&1; then
redis-server --requirepass "$REDIS_PASS" --daemonize yes
fi
# 生成初始 nginx 配置(默认指向 blue 18081若 blue 未部署则 18082
BACKEND=18081
[ -f "$APP_ROOT/.active" ] && [ "$(cat $APP_ROOT/.active)" = "green" ] && BACKEND=18082
sed "s/__BACKEND_PORT__/$BACKEND/g" "$APP_ROOT/nginx.conf.template" > "$APP_ROOT/nginx.conf"
# 若已有活跃实例,启动它
if [ -f "$APP_ROOT/.active" ]; then
ACTIVE=$(cat "$APP_ROOT/.active")
ACTIVE_DIR="$APP_ROOT/$ACTIVE"
if [ -d "$ACTIVE_DIR" ] && [ -x "$ACTIVE_DIR/soul-api" ]; then
PORT=18081
[ "$ACTIVE" = "green" ] && PORT=18082
cd "$ACTIVE_DIR"
export PORT=$PORT
export REDIS_URL="redis://:${REDIS_PASS}@127.0.0.1:6379/0"
nohup ./soul-api >> soul-api.log 2>&1 &
echo $! > "$APP_ROOT/.pid.$ACTIVE"
cd - >/dev/null
fi
fi
# 启动 Nginx前台保持容器运行
exec nginx -c "$APP_ROOT/nginx.conf" -g "daemon off;"