[jbe] deploy script & .env template mit Superuser-Cred für automatische DB-Anlage

This commit is contained in:
2026-08-16 11:18:16 +02:00
parent ec18084652
commit ae2f292fd5
2 changed files with 53 additions and 0 deletions
+4
View File
@@ -4,6 +4,10 @@ DB_USERNAME=immich
DB_PASSWORD=Gv4f_Gqhro_QrnM8v4hevdsPISbGDuXF
DB_PORT=5432
# PostgreSQL Superuser (für automatische DB-Anlage im deploy.sh)
PG_SUPERUSER=postgres
PG_SUPERPASS=iEoQsgDS5hLYQcTmG
REDIS_HOSTNAME=redis
REDIS_PORT=6379
REDIS_DATABASE=0
Executable
+49
View File
@@ -0,0 +1,49 @@
#!/bin/bash
set -euo pipefail
# Lade DB-Verbindungswerte aus .env
source .env
echo "[1/4] Sicherstellen, dass .env mit echten Werten existiert..."
test -f .env || { echo "Fehler: .env fehlt!"; exit 1; }
PG_SU_USER="${PG_SUPERUSER:-postgres}"
PG_SU_PASS="${PG_SUPERPASS:-}"
DB_HOST="${DB_HOSTNAME}"
DB_PORT="${DB_PORT:-5432}"
APP_DB="${DB_DATABASE}"
APP_USER="${DB_USERNAME}"
if [ -z "$PG_SU_PASS" ]; then
echo "Fehler: PG_SUPERUSER und/oder PG_SUPERPASS müssen in .env gesetzt sein."
exit 1
fi
echo "[2/4] PostgreSQL DB '${APP_DB}' prüfen/anlegen..."
export PGPASSWORD="${PG_SU_PASS}"
if ! psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${PG_SU_USER}" -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname = '${APP_DB}'" | grep -q 1; then
echo " Database wird angelegt..."
# Alte Backends trennen
psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${PG_SU_USER}" -d postgres -c \
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '${APP_DB}';" || true
sleep 2
psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${PG_SU_USER}" -d postgres -c \
"DROP DATABASE IF EXISTS ${APP_DB};" || true
sleep 2
psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${PG_SU_USER}" -d postgres -c \
"CREATE DATABASE ${APP_DB} OWNER ${APP_USER};"
else
echo " Database existiert bereits."
fi
echo "[3/4] Extensions sicherstellen..."
export PGPASSWORD="${DB_PASSWORD}"
psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${APP_USER}" -d "${APP_DB}" -c "CREATE EXTENSION IF NOT EXISTS vector;"
psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${APP_USER}" -d "${APP_DB}" -c "CREATE EXTENSION IF NOT EXISTS cube CASCADE;"
echo "[4/4] Upload-Verzeichnis erstellen und Stack starten..."
mkdir -p /mnt/docker/immich/upload
docker compose up -d --remove-orphans
echo ""
echo "Done. Logs prüfen mit: docker compose logs -f immich-server"