mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-07-08 15:01:00 +02:00
Update 99-run.sh
This commit is contained in:
@@ -11,9 +11,6 @@ mkdir -p /config/minio-data
|
|||||||
mkdir -p /config/postgres
|
mkdir -p /config/postgres
|
||||||
mkdir -p /config/scripts/compose
|
mkdir -p /config/scripts/compose
|
||||||
|
|
||||||
# Symlink
|
|
||||||
mv /museum /usr/bin/museum
|
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
# Config / options
|
# Config / options
|
||||||
############################################
|
############################################
|
||||||
@@ -41,14 +38,21 @@ if bashio::config.true 'DISABLE_WEB_UI'; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
# Paths to binaries
|
# Paths to binaries (discover; DO NOT mv)
|
||||||
############################################
|
############################################
|
||||||
INITDB="$(command -v initdb || echo /usr/bin/initdb)"
|
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"
|
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
|
||||||
|
|
||||||
|
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"
|
PGDATA="/config/postgres"
|
||||||
|
|
||||||
@@ -62,12 +66,10 @@ start_postgres() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# runtime socket dir
|
|
||||||
mkdir -p /run/postgresql
|
mkdir -p /run/postgresql
|
||||||
chown postgres:postgres /run/postgresql
|
chown postgres:postgres /run/postgresql
|
||||||
chmod 775 /run/postgresql
|
chmod 775 /run/postgresql
|
||||||
|
|
||||||
# data dir
|
|
||||||
mkdir -p "$PGDATA"
|
mkdir -p "$PGDATA"
|
||||||
chown -R postgres:postgres "$PGDATA"
|
chown -R postgres:postgres "$PGDATA"
|
||||||
chmod 0700 "$PGDATA"
|
chmod 0700 "$PGDATA"
|
||||||
@@ -78,26 +80,20 @@ 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=$!
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_postgres_ready() {
|
wait_postgres_ready() {
|
||||||
local host port user
|
local host port
|
||||||
if $USE_EXTERNAL_DB; then
|
if $USE_EXTERNAL_DB; then
|
||||||
host="$DB_HOST_EXT"
|
host="$DB_HOST_EXT"; port="$DB_PORT_EXT"
|
||||||
port="$DB_PORT_EXT"
|
|
||||||
user="$DB_USER"
|
|
||||||
bashio::log.info "Waiting for EXTERNAL Postgres at ${host}:${port}..."
|
bashio::log.info "Waiting for EXTERNAL Postgres at ${host}:${port}..."
|
||||||
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"
|
|
||||||
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"; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
bashio::log.info "Postgres reachable."
|
bashio::log.info "Postgres reachable."
|
||||||
@@ -110,22 +106,24 @@ bootstrap_internal_db() {
|
|||||||
|
|
||||||
bashio::log.info "Creating role/database if needed..."
|
bashio::log.info "Creating role/database if needed..."
|
||||||
|
|
||||||
# Create role if it doesn't exist, else update password to match config
|
local esc_pass="${DB_PASS//\'/\'\'}"
|
||||||
if ! psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname = '${DB_USER}'" | grep -q 1; then
|
|
||||||
|
# role
|
||||||
|
if ! psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \
|
||||||
|
"SELECT 1 FROM pg_roles WHERE rolname = '${DB_USER}'" | grep -q 1; then
|
||||||
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
||||||
-c "CREATE ROLE \"${DB_USER}\" LOGIN PASSWORD '${DB_PASS//\'/\'\'}';"
|
-c "CREATE ROLE \"${DB_USER}\" LOGIN PASSWORD '${esc_pass}';"
|
||||||
else
|
else
|
||||||
# update password in case it changed
|
|
||||||
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
||||||
-c "ALTER ROLE \"${DB_USER}\" PASSWORD '${DB_PASS//\'/\'\'}';"
|
-c "ALTER ROLE \"${DB_USER}\" PASSWORD '${esc_pass}';"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check and create database if it doesn't exist
|
# db
|
||||||
if ! psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc "SELECT 1 FROM pg_database WHERE datname = '${DB_NAME}'" | grep -q 1; then
|
if ! psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres -tAc \
|
||||||
|
"SELECT 1 FROM pg_database WHERE datname = '${DB_NAME}'" | grep -q 1; then
|
||||||
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
||||||
-c "CREATE DATABASE \"${DB_NAME}\" OWNER \"${DB_USER}\";"
|
-c "CREATE DATABASE \"${DB_NAME}\" OWNER \"${DB_USER}\";"
|
||||||
else
|
else
|
||||||
# Optional: ensure DB ownership
|
|
||||||
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
psql -v ON_ERROR_STOP=1 -h "$DB_HOST_INTERNAL" -p "$DB_PORT_INTERNAL" -U postgres \
|
||||||
-c "ALTER DATABASE \"${DB_NAME}\" OWNER TO \"${DB_USER}\";"
|
-c "ALTER DATABASE \"${DB_NAME}\" OWNER TO \"${DB_USER}\";"
|
||||||
fi
|
fi
|
||||||
@@ -155,6 +153,10 @@ start_web() {
|
|||||||
bashio::log.info "Web UI disabled."
|
bashio::log.info "Web UI disabled."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
if [ -z "$WEB_BIN" ] || [ ! -x "$WEB_BIN" ]; then
|
||||||
|
bashio::log.warning "Web UI binary not found; skipping."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
bashio::log.info "Starting Ente web (:3000)..."
|
bashio::log.info "Starting Ente web (:3000)..."
|
||||||
"$WEB_BIN" &
|
"$WEB_BIN" &
|
||||||
WEB_PID=$!
|
WEB_PID=$!
|
||||||
@@ -166,15 +168,26 @@ start_museum_foreground() {
|
|||||||
bashio::log.error "$cfg missing; cannot start museum."
|
bashio::log.error "$cfg missing; cannot start museum."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
if [ ! -x "$MUSEUM_BIN" ] && ! command -v "$MUSEUM_BIN" >/dev/null 2>&1; then
|
||||||
# For internal DB: wait one more time as DB_USER (ensures role exists)
|
bashio::log.error "Museum binary not found; cannot launch Ente API."
|
||||||
if ! $USE_EXTERNAL_DB; then
|
return 1
|
||||||
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
|
|
||||||
fi
|
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
|
||||||
|
|
||||||
bashio::log.info "Starting museum (foreground)..."
|
bashio::log.info "Starting museum (foreground)..."
|
||||||
exec "$MUSEUM_BIN" --config "$cfg"
|
exec "$MUSEUM_BIN" --config "$cfg"
|
||||||
}
|
}
|
||||||
@@ -193,5 +206,4 @@ wait_minio_ready_and_bucket
|
|||||||
|
|
||||||
start_web
|
start_web
|
||||||
|
|
||||||
# Last: foreground museum keeps container alive
|
|
||||||
start_museum_foreground
|
start_museum_foreground
|
||||||
|
|||||||
Reference in New Issue
Block a user