Spaces:
Runtime error
Runtime error
Update entrypoint.sh
Browse files- entrypoint.sh +17 -23
entrypoint.sh
CHANGED
|
@@ -1,45 +1,39 @@
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 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
|
| 12 |
-
|
| 13 |
PG_BIN=$(pg_config --bindir 2>/dev/null || echo "/usr/lib/postgresql/15/bin")
|
| 14 |
-
|
| 15 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
+
# ★ /data と /data/exports を必ず作成
|
| 5 |
+
mkdir -p /data /data/exports
|
| 6 |
|
| 7 |
+
start_postgres() {
|
| 8 |
+
echo "[init] starting internal postgres..."
|
|
|
|
|
|
|
| 9 |
mkdir -p /data/postgres
|
| 10 |
+
chown -R postgres:postgres /data/postgres
|
|
|
|
| 11 |
PG_BIN=$(pg_config --bindir 2>/dev/null || echo "/usr/lib/postgresql/15/bin")
|
| 12 |
+
su - postgres -s /bin/bash -c "$PG_BIN/initdb -D /data/postgres" || true
|
| 13 |
+
su - postgres -s /bin/bash -c "$PG_BIN/pg_ctl -D /data/postgres -l /data/postgres/logfile start"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
sleep 2
|
| 15 |
+
su - postgres -s /bin/bash -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}';\""
|
| 16 |
+
su - postgres -s /bin/bash -c "psql -lqt | cut -d '|' -f 1 | grep -qw ${POSTGRES_DB} || createdb -O ${POSTGRES_USER} ${POSTGRES_DB}"
|
| 17 |
+
echo "[ok] postgres is up"
|
| 18 |
+
}
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
echo "[entrypoint] Starting redis-server..."
|
| 21 |
/usr/bin/redis-server --save "" --appendonly no &
|
| 22 |
|
| 23 |
+
if [ "${USE_INTERNAL_POSTGRES}" = "true" ]; then
|
| 24 |
+
start_postgres
|
| 25 |
+
else
|
| 26 |
+
echo "[entrypoint] USE_INTERNAL_POSTGRES != true (using SQLite)"
|
| 27 |
+
fi
|
| 28 |
+
|
| 29 |
echo "[entrypoint] Starting celery worker..."
|
| 30 |
cd /app
|
| 31 |
celery -A app.tasks.celery_app worker --loglevel=INFO &
|
| 32 |
|
|
|
|
| 33 |
echo "[entrypoint] Starting uvicorn..."
|
| 34 |
python -m app.main &
|
| 35 |
|
|
|
|
| 36 |
echo "[entrypoint] Running init_db bootstrap..."
|
| 37 |
python /app/scripts/init_db.py || true
|
| 38 |
|
|
|
|
| 39 |
wait -n
|