From 6ee4175ae6219b454dad6415755d870c41ef9d53 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 17 Jul 2025 16:43:06 +0200 Subject: [PATCH] Update 99-run.sh --- ente/rootfs/etc/cont-init.d/99-run.sh | 332 +++++++++++++++----------- 1 file changed, 194 insertions(+), 138 deletions(-) diff --git a/ente/rootfs/etc/cont-init.d/99-run.sh b/ente/rootfs/etc/cont-init.d/99-run.sh index 1e82ec4ee..4299438f8 100755 --- a/ente/rootfs/etc/cont-init.d/99-run.sh +++ b/ente/rootfs/etc/cont-init.d/99-run.sh @@ -3,42 +3,65 @@ set -euo pipefail ############################################ -# Persistent dirs +# Paths & constants ############################################ -mkdir -p /config/ente/custom-logs -mkdir -p /config/data -mkdir -p /config/minio-data -mkdir -p /config/postgres -mkdir -p /config/scripts/compose +CFG=/config/museum.yaml +PGDATA=/config/postgres -############################################ -# Config / options -############################################ -USE_EXTERNAL_DB=false -if bashio::config.true 'USE_EXTERNAL_DB'; then - USE_EXTERNAL_DB=true -fi - -DB_NAME="$(bashio::config 'DB_DATABASE_NAME')" -DB_USER="$(bashio::config 'DB_USERNAME')" -DB_PASS="$(bashio::config 'DB_PASSWORD')" +# Internal Postgres always bound here DB_HOST_INTERNAL=127.0.0.1 DB_PORT_INTERNAL=5432 -DB_HOST_EXT="$(bashio::config 'DB_HOSTNAME')" -DB_PORT_EXT="$(bashio::config 'DB_PORT')" +############################################ +# Read add‑on options +############################################ +DB_NAME="$(bashio::config 'DB_DATABASE_NAME' || echo ente_db)" +DB_USER="$(bashio::config 'DB_USERNAME' || echo pguser)" +DB_PASS="$(bashio::config 'DB_PASSWORD' || echo ente)" + +# External DB opts (may be blank) +DB_HOST_EXT="$(bashio::config 'DB_HOSTNAME' || echo '')" +DB_PORT_EXT="$(bashio::config 'DB_PORT' || echo '')" MINIO_USER="$(bashio::config 'MINIO_ROOT_USER')" MINIO_PASS="$(bashio::config 'MINIO_ROOT_PASSWORD')" + +# Which bucket name we’ll auto‑create in MinIO S3_BUCKET="b2-eu-cen" +USE_EXTERNAL_DB=false +if bashio::config.true 'USE_EXTERNAL_DB'; then + USE_EXTERNAL_DB=true + bashio::log.warning "USE_EXTERNAL_DB enabled: will connect to external Postgres." +else + bashio::log.info "Using internal Postgres." +fi + DISABLE_WEB_UI=false if bashio::config.true 'DISABLE_WEB_UI'; then - DISABLE_WEB_UI=true + DISABLE_WEB_UI=true +fi + +# Active DB connection target (may be overridden below) +if $USE_EXTERNAL_DB; then + DB_HOST="$DB_HOST_EXT" + DB_PORT="$DB_PORT_EXT" +else + DB_HOST="$DB_HOST_INTERNAL" + DB_PORT="$DB_PORT_INTERNAL" fi ############################################ -# Paths to binaries (discover; DO NOT mv) +# Ensure persistent dirs +############################################ +mkdir -p /config/ente/custom-logs \ + /config/data \ + /config/minio-data \ + "$PGDATA" \ + /config/scripts/compose + +############################################ +# Locate binaries ############################################ INITDB="$(command -v initdb || echo /usr/bin/initdb)" POSTGRES_BIN="$(command -v postgres || echo /usr/bin/postgres)" @@ -48,160 +71,186 @@ MC_BIN="/usr/local/bin/mc" MUSEUM_BIN="$(command -v museum || true)" [ -z "$MUSEUM_BIN" ] && [ -x /app/museum ] && MUSEUM_BIN=/app/museum [ -z "$MUSEUM_BIN" ] && [ -x /museum ] && MUSEUM_BIN=/museum -[ -z "$MUSEUM_BIN" ] && MUSEUM_BIN=museum # last resort: PATH +[ -z "$MUSEUM_BIN" ] && MUSEUM_BIN=museum -WEB_BIN="$(command -v ente-web || true)" -[ -z "$WEB_BIN" ] && [ -x /app/ente-web ] && WEB_BIN=/app/ente-web -[ -z "$WEB_BIN" ] && [ -x /ente-web ] && WEB_BIN=/ente-web - -PGDATA="/config/postgres" +WEB_PREP_BIN=/usr/local/bin/ente-web-prepare +WEB_NGINX_CONF=/etc/ente-web/nginx.conf ############################################ -# Functions +# Config generation ############################################ +create_config() { + bashio::log.info "Generating new museum config at $CFG" + # small helpers + _rand_b64() { head -c "$1" /dev/urandom | base64 | tr -d '\n'; } + _rand_b64url() { head -c "$1" /dev/urandom | base64 | tr '+/' '-_' | tr -d '\n'; } + cat >"$CFG" </dev/null; do - sleep 1 - done - bashio::log.info "Ensuring bucket..." - "$MC_BIN" mb -p h0/b2-eu-cen || true - "$MC_BIN" mb -p h0/wasabi-eu-central-2-v3 || true - "$MC_BIN" mb -p h0/scw-eu-fr-v3 || true - bashio::log.info "MinIO bucket ready." + bashio::log.info "Waiting for MinIO API..." + until "$MC_BIN" alias set h0 http://127.0.0.1:3200 "$MINIO_USER" "$MINIO_PASS" 2>/dev/null; do + sleep 1 + done + bashio::log.info "Ensuring buckets..." + "$MC_BIN" mb -p "h0/${S3_BUCKET}" || true + "$MC_BIN" mb -p "h0/wasabi-eu-central-2-v3" || true + "$MC_BIN" mb -p "h0/scw-eu-fr-v3" || true + bashio::log.info "MinIO buckets ready." } +############################################ +# Web (static nginx bundle) +############################################ start_web() { - if $DISABLE_WEB_UI; then - bashio::log.info "Web UI disabled." - return 0 - fi + if $DISABLE_WEB_UI; then + bashio::log.info "Web UI disabled." + return 0 + fi - # Prepare static assets with actual origins (does safe sed replacements). - ENTE_API_ORIGIN="${ENTE_API_ORIGIN:-http://[HOST]:[PORT:8080]}" - ENTE_ALBUMS_ORIGIN="${ENTE_ALBUMS_ORIGIN:-${ENTE_API_ORIGIN}}" - export ENTE_API_ORIGIN ENTE_ALBUMS_ORIGIN - /usr/local/bin/ente-web-prepare || bashio::log.warning "Web env substitution step returned non‑zero; continuing." + ENTE_API_ORIGIN="${ENTE_API_ORIGIN:-http://[HOST]:[PORT:8080]}" + ENTE_ALBUMS_ORIGIN="${ENTE_ALBUMS_ORIGIN:-${ENTE_API_ORIGIN}}" + export ENTE_API_ORIGIN ENTE_ALBUMS_ORIGIN - # nginx expects runtime dirs - mkdir -p /run/nginx - # log dir - mkdir -p /var/log/nginx + if [ -x "$WEB_PREP_BIN" ]; then + "$WEB_PREP_BIN" || bashio::log.warning "Web env substitution step failed (non‑fatal)." + else + bashio::log.warning "Web prep helper not found ($WEB_PREP_BIN); skipping substitution." + fi - bashio::log.info "Starting Ente web (nginx, ports 3000‑3004)..." - nginx -c /etc/ente-web/nginx.conf -g 'daemon off;' & - WEB_PID=$! + mkdir -p /run/nginx /var/log/nginx + if [ ! -f "$WEB_NGINX_CONF" ]; then + bashio::log.error "Missing nginx conf at $WEB_NGINX_CONF; cannot start web." + return 1 + fi + + bashio::log.info "Starting Ente web (nginx, ports 3000‑3004)..." + nginx -c "$WEB_NGINX_CONF" -g 'daemon off;' & + WEB_PID=$! } +############################################ +# Museum (API) +############################################ start_museum_foreground() { - local cfg=/config/museum.yaml - if ! bashio::fs.file_exists "$cfg"; then - bashio::log.error "$cfg missing; cannot start museum." - return 1 - fi - if [ ! -x "$MUSEUM_BIN" ] && ! command -v "$MUSEUM_BIN" >/dev/null 2>&1; then - bashio::log.error "Museum binary not found; cannot launch Ente API." - return 1 - fi + if [ ! -f "$CFG" ]; then + bashio::log.error "$CFG missing; cannot start museum." + return 1 + fi + if [ ! -x "$MUSEUM_BIN" ] && ! command -v "$MUSEUM_BIN" >/dev/null 2>&1; then + bashio::log.error "Museum binary not found; cannot launch Ente API." + return 1 + fi - # Export ENTE_* overrides to guarantee correct credentials parsing. - # (Museum merges env vars over YAML.) - # Ref: environment override mechanism in museum docs. :contentReference[oaicite:2]{index=2} - if $USE_EXTERNAL_DB; then - export ENTE_DB_HOST="$DB_HOST_EXT" - export ENTE_DB_PORT="$DB_PORT_EXT" - else - export ENTE_DB_HOST="$DB_HOST_INTERNAL" - export ENTE_DB_PORT="$DB_PORT_INTERNAL" - fi - export ENTE_DB_USER="$DB_USER" - export ENTE_DB_PASSWORD="$DB_PASS" - export ENTE_DB_NAME="$DB_NAME" - export ENTE_DB_SSLMODE=disable + # Force env overrides (museum merges env > yaml) + if $USE_EXTERNAL_DB; then + export ENTE_DB_HOST="$DB_HOST_EXT" + export ENTE_DB_PORT="$DB_PORT_EXT" + else + export ENTE_DB_HOST="$DB_HOST_INTERNAL" + export ENTE_DB_PORT="$DB_PORT_INTERNAL" + fi + export ENTE_DB_USER="$DB_USER" + export ENTE_DB_PASSWORD="$DB_PASS" + export ENTE_DB_NAME="$DB_NAME" + export ENTE_DB_SSLMODE=disable - bashio::log.info "Starting museum (foreground)..." - exec "$MUSEUM_BIN" --config "$cfg" + bashio::log.info "Starting museum (foreground)..." + exec "$MUSEUM_BIN" --config "$CFG" } ############################################ @@ -209,6 +258,12 @@ start_museum_foreground() { ############################################ bashio::log.info "=== Ente startup sequence ===" +if [ ! -f "$CFG" ]; then + create_config +else + bashio::log.info "Using existing $CFG." +fi + start_postgres wait_postgres_ready bootstrap_internal_db @@ -218,4 +273,5 @@ wait_minio_ready_and_bucket start_web +# Foreground (keeps container alive) start_museum_foreground