Update hf-entrypoint.sh
Browse files- hf-entrypoint.sh +21 -28
hf-entrypoint.sh
CHANGED
|
@@ -28,11 +28,12 @@ if [ ! -s "${PGDATA}/PG_VERSION" ]; then
|
|
| 28 |
run_as_postgres initdb -D "${PGDATA}" >/dev/null
|
| 29 |
fi
|
| 30 |
|
|
|
|
| 31 |
run_as_postgres pg_ctl -D "${PGDATA}" \
|
| 32 |
-o "-c listen_addresses=127.0.0.1 -c port=5432 -c unix_socket_directories=/tmp" \
|
| 33 |
-w start
|
| 34 |
|
| 35 |
-
#
|
| 36 |
run_as_postgres psql -h 127.0.0.1 -p 5432 -v ON_ERROR_STOP=1 --username postgres --dbname postgres <<SQL
|
| 37 |
DO \$\$
|
| 38 |
BEGIN
|
|
@@ -45,7 +46,7 @@ END
|
|
| 45 |
\$\$;
|
| 46 |
SQL
|
| 47 |
|
| 48 |
-
#
|
| 49 |
DB_EXISTS=$(run_as_postgres psql -h 127.0.0.1 -p 5432 -U postgres -d postgres -tAc \
|
| 50 |
"SELECT 1 FROM pg_database WHERE datname='${POSTGRES_DB}'")
|
| 51 |
|
|
@@ -59,33 +60,25 @@ export DB_URL="${DATABASE_URL}"
|
|
| 59 |
export REDIS_URL="${REDIS_URL:-redis://127.0.0.1:6379/0}"
|
| 60 |
export PORT="${PORT:-8080}"
|
| 61 |
export HOST="${HOST:-0.0.0.0}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
echo "[boot] DATABASE_URL
|
| 64 |
echo "[boot] REDIS_URL=${REDIS_URL}"
|
| 65 |
echo "[boot] APP_PORT=${PORT}"
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
# 优先手动指定
|
| 72 |
-
if [ -n "${SUB2API_CMD:-}" ]; then
|
| 73 |
-
exec bash -lc "${SUB2API_CMD}"
|
| 74 |
-
fi
|
| 75 |
-
|
| 76 |
-
# 自动回退:按常见入口顺序尝试
|
| 77 |
-
if [ -x /docker-entrypoint.sh ]; then
|
| 78 |
-
exec /docker-entrypoint.sh
|
| 79 |
-
elif [ -x /entrypoint.sh ]; then
|
| 80 |
-
exec /entrypoint.sh
|
| 81 |
-
elif command -v sub2api >/dev/null 2>&1; then
|
| 82 |
-
exec sub2api
|
| 83 |
-
elif [ -x /app/sub2api ]; then
|
| 84 |
-
exec /app/sub2api
|
| 85 |
-
fi
|
| 86 |
-
|
| 87 |
-
echo "[error] cannot find original sub2api entrypoint"
|
| 88 |
-
exit 1
|
| 89 |
-
|
| 90 |
-
echo "[error] No CMD found. Please set Space variable SUB2API_CMD"
|
| 91 |
-
exit 1
|
|
|
|
| 28 |
run_as_postgres initdb -D "${PGDATA}" >/dev/null
|
| 29 |
fi
|
| 30 |
|
| 31 |
+
# Place Unix socket under /tmp to avoid missing /run/postgresql in HF runtime.
|
| 32 |
run_as_postgres pg_ctl -D "${PGDATA}" \
|
| 33 |
-o "-c listen_addresses=127.0.0.1 -c port=5432 -c unix_socket_directories=/tmp" \
|
| 34 |
-w start
|
| 35 |
|
| 36 |
+
# Upsert DB role.
|
| 37 |
run_as_postgres psql -h 127.0.0.1 -p 5432 -v ON_ERROR_STOP=1 --username postgres --dbname postgres <<SQL
|
| 38 |
DO \$\$
|
| 39 |
BEGIN
|
|
|
|
| 46 |
\$\$;
|
| 47 |
SQL
|
| 48 |
|
| 49 |
+
# CREATE DATABASE cannot run inside DO block. Check first, then createdb.
|
| 50 |
DB_EXISTS=$(run_as_postgres psql -h 127.0.0.1 -p 5432 -U postgres -d postgres -tAc \
|
| 51 |
"SELECT 1 FROM pg_database WHERE datname='${POSTGRES_DB}'")
|
| 52 |
|
|
|
|
| 60 |
export REDIS_URL="${REDIS_URL:-redis://127.0.0.1:6379/0}"
|
| 61 |
export PORT="${PORT:-8080}"
|
| 62 |
export HOST="${HOST:-0.0.0.0}"
|
| 63 |
+
export AUTO_SETUP="${AUTO_SETUP:-true}"
|
| 64 |
+
export SERVER_HOST="${HOST}"
|
| 65 |
+
export SERVER_PORT="${PORT}"
|
| 66 |
+
export DATABASE_HOST="${DATABASE_HOST:-127.0.0.1}"
|
| 67 |
+
export DATABASE_PORT="${DATABASE_PORT:-5432}"
|
| 68 |
+
export DATABASE_USER="${POSTGRES_USER}"
|
| 69 |
+
export DATABASE_PASSWORD="${POSTGRES_PASSWORD}"
|
| 70 |
+
export DATABASE_DBNAME="${POSTGRES_DB}"
|
| 71 |
+
export DATABASE_SSLMODE="${DATABASE_SSLMODE:-disable}"
|
| 72 |
+
export REDIS_HOST="${REDIS_HOST:-127.0.0.1}"
|
| 73 |
+
export REDIS_PORT="${REDIS_PORT:-6379}"
|
| 74 |
+
export REDIS_DB="${REDIS_DB:-0}"
|
| 75 |
+
export REDIS_PASSWORD="${REDIS_PASSWORD:-}"
|
| 76 |
+
export REDIS_ENABLE_TLS="${REDIS_ENABLE_TLS:-false}"
|
| 77 |
|
| 78 |
+
echo "[boot] DATABASE_URL=postgresql://${POSTGRES_USER}:******@127.0.0.1:5432/${POSTGRES_DB}"
|
| 79 |
echo "[boot] REDIS_URL=${REDIS_URL}"
|
| 80 |
echo "[boot] APP_PORT=${PORT}"
|
| 81 |
|
| 82 |
+
# Start sub2api with the original entrypoint discovered from the base image.
|
| 83 |
+
mkdir -p /app/data
|
| 84 |
+
exec /app/sub2api
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|