63 lines
1.7 KiB
Bash
63 lines
1.7 KiB
Bash
#!/bin/sh
|
||
set -eu
|
||
|
||
# 强制 production(与官方 docker-compose.production.yaml 一致)
|
||
export RAILS_ENV=production
|
||
export NODE_ENV=production
|
||
export INSTALLATION_ENV=docker
|
||
export RAILS_SERVE_STATIC_FILES=true
|
||
export BUNDLE_WITHOUT="${BUNDLE_WITHOUT:-development:test}"
|
||
export EXECJS_RUNTIME="${EXECJS_RUNTIME:-Disabled}"
|
||
export APP_DEBUG=false
|
||
|
||
cd /app
|
||
|
||
rm -rf /app/tmp/pids/server.pid
|
||
rm -rf /app/tmp/cache/*
|
||
|
||
echo "[guest-cs] Waiting for postgres..."
|
||
# shellcheck disable=SC2046
|
||
eval $(docker/entrypoints/helpers/pg_database_url.rb)
|
||
PG_READY="pg_isready -h $POSTGRES_HOST -p ${POSTGRES_PORT:-5432} -U $POSTGRES_USERNAME"
|
||
until $PG_READY; do
|
||
sleep 2
|
||
done
|
||
echo "[guest-cs] Database ready."
|
||
|
||
# 空库首次启动:初始化 schema(官方生产流程 db:chatwoot_prepare)
|
||
echo "[guest-cs] Ensuring Chatwoot DB schema..."
|
||
bundle exec rails db:chatwoot_prepare
|
||
|
||
# production 镜像已含编译前端与 gems,不做 bundle install / pnpm(那是 development)
|
||
|
||
echo "[guest-cs] starting sidekiq (production)..."
|
||
bundle exec sidekiq -C config/sidekiq.yml &
|
||
SIDEKIQ_PID=$!
|
||
|
||
echo "[guest-cs] starting rails :3000 (production, static assets)..."
|
||
bundle exec rails s -p 3000 -b 0.0.0.0 &
|
||
RAILS_PID=$!
|
||
|
||
echo "[guest-cs] starting flask :7788 (gunicorn)..."
|
||
cd /opt/guest-cs
|
||
/opt/guest-cs/.venv/bin/gunicorn --bind 0.0.0.0:7788 --workers 2 --threads 4 --timeout 120 wsgi:application &
|
||
FLASK_PID=$!
|
||
|
||
_term() {
|
||
echo "[guest-cs] shutting down..."
|
||
kill -TERM "$FLASK_PID" "$RAILS_PID" "$SIDEKIQ_PID" 2>/dev/null || true
|
||
wait || true
|
||
}
|
||
trap _term TERM INT
|
||
|
||
while true; do
|
||
for pid in "$SIDEKIQ_PID" "$RAILS_PID" "$FLASK_PID"; do
|
||
if ! kill -0 "$pid" 2>/dev/null; then
|
||
echo "[guest-cs] process $pid exited"
|
||
_term
|
||
exit 1
|
||
fi
|
||
done
|
||
sleep 2
|
||
done
|