From deb5a7fd3adec50d2dbc274b1381077401fe10b1 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 16 Jul 2025 21:50:34 +0200 Subject: [PATCH] Update 99-run.sh --- ente/rootfs/etc/cont-init.d/99-run.sh | 86 ++++++++------------------- 1 file changed, 24 insertions(+), 62 deletions(-) diff --git a/ente/rootfs/etc/cont-init.d/99-run.sh b/ente/rootfs/etc/cont-init.d/99-run.sh index 890385b47..32e7ff04b 100644 --- a/ente/rootfs/etc/cont-init.d/99-run.sh +++ b/ente/rootfs/etc/cont-init.d/99-run.sh @@ -44,39 +44,8 @@ INITDB="$(command -v initdb || echo /usr/bin/initdb)" POSTGRES_BIN="$(command -v postgres || echo /usr/bin/postgres)" MINIO_BIN="/usr/local/bin/minio" MC_BIN="/usr/local/bin/mc" - -# runtime binary resolver -resolve_bin() { - local name="$1" - shift - local cand - for cand in "$@"; do - [ -x "$cand" ] && { - echo "$cand" - return 0 - } - done - cand="$(command -v "$name" 2>/dev/null || true)" - [ -n "$cand" ] && { - echo "$cand" - return 0 - } - echo "" - return 1 -} - -MUSEUM_BIN="$(resolve_bin museum /usr/bin/museum /usr/local/bin/museum /app/museum /museum)" -WEB_BIN="$(resolve_bin ente-web /usr/bin/ente-web /usr/local/bin/ente-web /app/ente-web /ente-web)" - -if [ -z "$MUSEUM_BIN" ]; then - bashio::log.error "museum binary not found; cannot start Ente API." - exit 1 -fi - -if ! $DISABLE_WEB_UI && [ -z "$WEB_BIN" ]; then - bashio::log.warning "Ente web binary not found; disabling web UI." - DISABLE_WEB_UI=true -fi +MUSEUM_BIN="/usr/bin/museum" +WEB_BIN="/usr/bin/ente-web" PGDATA="/config/postgres" @@ -106,6 +75,7 @@ start_postgres() { fi bashio::log.info "Starting Postgres (127.0.0.1:5432)..." + # background so startup can continue su - postgres -c "$POSTGRES_BIN -D $PGDATA -c listen_addresses='127.0.0.1'" & PG_PID=$! } @@ -120,7 +90,8 @@ wait_postgres_ready() { else host="$DB_HOST_INTERNAL" port="$DB_PORT_INTERNAL" - user="postgres" # superuser for first readiness check + # Use superuser 'postgres' for readiness check because DB_USER may not yet exist. + user="postgres" bashio::log.info "Waiting for internal Postgres..." fi until pg_isready -q -h "$host" -p "$port" -U "$user"; do @@ -133,27 +104,21 @@ bootstrap_internal_db() { if $USE_EXTERNAL_DB; then return 0 fi + bashio::log.info "Creating role/database if needed..." - bashio::log.info "Ensuring role ${DB_USER} exists..." - if ! psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \ - "SELECT 1 FROM pg_roles WHERE rolname='${DB_USER}'" | - grep -q 1; then - # password quoting: single quotes doubled - esc_pass="${DB_PASS//\'/\'\'}" - psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \ - "CREATE ROLE ${DB_USER} LOGIN PASSWORD '${esc_pass}'" || true - else - psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \ - "ALTER ROLE ${DB_USER} LOGIN PASSWORD '${DB_PASS//\'/\'\'}'" >/dev/null 2>&1 || true - fi - bashio::log.info "Ensuring database ${DB_NAME} exists (owner ${DB_USER})..." - if ! psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \ - "SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" | - grep -q 1; then - # CREATE DATABASE must be top-level (not in DO/transaction). :contentReference[oaicite:2]{index=2} - psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \ - "CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}" - fi + # Use psql via local socket (faster, avoids password) + psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres </dev/null 2>&1; do + bashio::log.info "Verifying internal DB user '${DB_USER}'..." + until pg_isready -q -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U "$DB_USER"; do sleep 1 done - else - bashio::log.info "Using external DB; skipping final local verification." fi - bashio::log.info "Starting museum (foreground) using $MUSEUM_BIN ..." - # museum loads /config/museum.yaml to override defaults. :contentReference[oaicite:3]{index=3} + bashio::log.info "Starting museum (foreground)..." exec "$MUSEUM_BIN" --config "$cfg" }