Spaces:
Runtime error
Runtime error
Update entrypoint.sh
Browse files- entrypoint.sh +35 -16
entrypoint.sh
CHANGED
|
@@ -1,26 +1,45 @@
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
-
|
| 5 |
-
mkdir -p /data/exports /var/log/supervisor
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
if [
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
/usr/bin/supervisord -c "$SUP_CONF" &
|
| 17 |
-
else
|
| 18 |
-
echo "No supervisord config found. Exiting."
|
| 19 |
-
exit 2
|
| 20 |
fi
|
| 21 |
|
| 22 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
python /app/scripts/init_db.py || true
|
| 24 |
|
| 25 |
-
#
|
| 26 |
wait -n
|
|
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
+
mkdir -p /data/exports
|
|
|
|
| 5 |
|
| 6 |
+
# ---------------- Optional: Internal Postgres ----------------
|
| 7 |
+
# USE_INTERNAL_POSTGRES=true のときだけ内部で起動(既定は SQLite)
|
| 8 |
+
if [ "$USE_INTERNAL_POSTGRES" = "true" ]; then
|
| 9 |
+
echo "[entrypoint] Starting internal Postgres..."
|
| 10 |
+
mkdir -p /data/postgres
|
| 11 |
+
chown -R postgres:postgres /data/postgres || true
|
| 12 |
+
|
| 13 |
+
PG_BIN=$(pg_config --bindir 2>/dev/null || echo "/usr/lib/postgresql/15/bin")
|
| 14 |
+
|
| 15 |
+
# initdb(既に初期化済みならスキップ)
|
| 16 |
+
su - postgres -c "$PG_BIN/initdb -D /data/postgres" || true
|
| 17 |
+
|
| 18 |
+
# 起動
|
| 19 |
+
su - postgres -c "$PG_BIN/pg_ctl -D /data/postgres -l /data/postgres/logfile start"
|
| 20 |
+
sleep 2
|
| 21 |
|
| 22 |
+
# ユーザー & DB を作成(存在しない場合のみ)
|
| 23 |
+
su - postgres -c "psql -tc \"SELECT 1 FROM pg_roles WHERE rolname='${POSTGRES_USER}'\" | grep -q 1 || psql -c \"CREATE USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}';\""
|
| 24 |
+
su - postgres -c "psql -lqt | cut -d \| -f 1 | grep -qw ${POSTGRES_DB} || createdb -O ${POSTGRES_USER} ${POSTGRES_DB}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
fi
|
| 26 |
|
| 27 |
+
# ---------------- Redis ----------------
|
| 28 |
+
echo "[entrypoint] Starting redis-server..."
|
| 29 |
+
/usr/bin/redis-server --save "" --appendonly no &
|
| 30 |
+
|
| 31 |
+
# ---------------- Celery ----------------
|
| 32 |
+
echo "[entrypoint] Starting celery worker..."
|
| 33 |
+
cd /app
|
| 34 |
+
celery -A app.tasks.celery_app worker --loglevel=INFO &
|
| 35 |
+
|
| 36 |
+
# ---------------- FastAPI (Uvicorn) ----------------
|
| 37 |
+
echo "[entrypoint] Starting uvicorn..."
|
| 38 |
+
python -m app.main &
|
| 39 |
+
|
| 40 |
+
# ---------------- One-shot DB bootstrap ----------------
|
| 41 |
+
echo "[entrypoint] Running init_db bootstrap..."
|
| 42 |
python /app/scripts/init_db.py || true
|
| 43 |
|
| 44 |
+
# ---------------- Wait on background processes ----------------
|
| 45 |
wait -n
|