mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-12 18:41:27 +02:00
Update 99-run.sh
This commit is contained in:
@@ -44,8 +44,32 @@ INITDB="$(command -v initdb || echo /usr/bin/initdb)"
|
|||||||
POSTGRES_BIN="$(command -v postgres || echo /usr/bin/postgres)"
|
POSTGRES_BIN="$(command -v postgres || echo /usr/bin/postgres)"
|
||||||
MINIO_BIN="/usr/local/bin/minio"
|
MINIO_BIN="/usr/local/bin/minio"
|
||||||
MC_BIN="/usr/local/bin/mc"
|
MC_BIN="/usr/local/bin/mc"
|
||||||
MUSEUM_BIN="/usr/bin/museum"
|
|
||||||
WEB_BIN="/usr/bin/ente-web"
|
# 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
|
||||||
|
|
||||||
PGDATA="/config/postgres"
|
PGDATA="/config/postgres"
|
||||||
|
|
||||||
@@ -75,7 +99,6 @@ start_postgres() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
bashio::log.info "Starting Postgres (127.0.0.1:5432)..."
|
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'" &
|
su - postgres -c "$POSTGRES_BIN -D $PGDATA -c listen_addresses='127.0.0.1'" &
|
||||||
PG_PID=$!
|
PG_PID=$!
|
||||||
}
|
}
|
||||||
@@ -90,8 +113,7 @@ wait_postgres_ready() {
|
|||||||
else
|
else
|
||||||
host="$DB_HOST_INTERNAL"
|
host="$DB_HOST_INTERNAL"
|
||||||
port="$DB_PORT_INTERNAL"
|
port="$DB_PORT_INTERNAL"
|
||||||
# Use superuser 'postgres' for readiness check because DB_USER may not yet exist.
|
user="postgres" # superuser for first readiness check
|
||||||
user="postgres"
|
|
||||||
bashio::log.info "Waiting for internal Postgres..."
|
bashio::log.info "Waiting for internal Postgres..."
|
||||||
fi
|
fi
|
||||||
until pg_isready -q -h "$host" -p "$port" -U "$user"; do
|
until pg_isready -q -h "$host" -p "$port" -U "$user"; do
|
||||||
@@ -104,21 +126,27 @@ bootstrap_internal_db() {
|
|||||||
if $USE_EXTERNAL_DB; then
|
if $USE_EXTERNAL_DB; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
bashio::log.info "Creating role/database if needed..."
|
|
||||||
|
|
||||||
# Use psql via local socket (faster, avoids password)
|
bashio::log.info "Ensuring role ${DB_USER} exists..."
|
||||||
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres <<SQL
|
if ! psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \
|
||||||
DO \$\$
|
"SELECT 1 FROM pg_roles WHERE rolname='${DB_USER}'" \
|
||||||
BEGIN
|
| grep -q 1; then
|
||||||
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '${DB_USER}') THEN
|
# password quoting: single quotes doubled
|
||||||
EXECUTE 'CREATE ROLE ${DB_USER} LOGIN PASSWORD ''' || replace('${DB_PASS}','''','''''') || '''';
|
esc_pass="${DB_PASS//\'/\'\'}"
|
||||||
END IF;
|
psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \
|
||||||
IF NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = '${DB_NAME}') THEN
|
"CREATE ROLE ${DB_USER} LOGIN PASSWORD '${esc_pass}'" || true
|
||||||
EXECUTE 'CREATE DATABASE ${DB_NAME} OWNER ${DB_USER}';
|
else
|
||||||
END IF;
|
psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -c \
|
||||||
END
|
"ALTER ROLE ${DB_USER} LOGIN PASSWORD '${DB_PASS//\'/\'\'}'" >/dev/null 2>&1 || true
|
||||||
\$\$;
|
fi
|
||||||
SQL
|
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
|
||||||
|
|
||||||
bashio::log.info "Internal Postgres ready."
|
bashio::log.info "Internal Postgres ready."
|
||||||
}
|
}
|
||||||
@@ -145,7 +173,7 @@ start_web() {
|
|||||||
bashio::log.info "Web UI disabled."
|
bashio::log.info "Web UI disabled."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
bashio::log.info "Starting Ente web (:3000)..."
|
bashio::log.info "Starting Ente web (:3000) using $WEB_BIN ..."
|
||||||
"$WEB_BIN" &
|
"$WEB_BIN" &
|
||||||
WEB_PID=$!
|
WEB_PID=$!
|
||||||
}
|
}
|
||||||
@@ -157,15 +185,18 @@ start_museum_foreground() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For internal DB: wait one more time as DB_USER (ensures role exists)
|
# For internal DB: verify reached DB_NAME
|
||||||
if ! $USE_EXTERNAL_DB; then
|
if ! $USE_EXTERNAL_DB; then
|
||||||
bashio::log.info "Verifying internal DB user '${DB_USER}'..."
|
bashio::log.info "Verifying internal DB '${DB_NAME}' as '${DB_USER}'..."
|
||||||
until pg_isready -q -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U "$DB_USER"; do
|
until PGPASSWORD="$DB_PASS" psql -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U "$DB_USER" -d "$DB_NAME" -c 'SELECT 1;' >/dev/null 2>&1; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
else
|
||||||
|
bashio::log.info "Using external DB; skipping final local verification."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bashio::log.info "Starting museum (foreground)..."
|
bashio::log.info "Starting museum (foreground) using $MUSEUM_BIN ..."
|
||||||
|
# museum loads /config/museum.yaml to override defaults. :contentReference[oaicite:3]{index=3}
|
||||||
exec "$MUSEUM_BIN" --config "$cfg"
|
exec "$MUSEUM_BIN" --config "$cfg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user