#!/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;"