diff --git a/run-document-server.sh b/run-document-server.sh index 4f083e08d..16a43ab39 100644 --- a/run-document-server.sh +++ b/run-document-server.sh @@ -267,12 +267,24 @@ if [ "${DB_HOST}" = "localhost" ]; then fi # Force trust authentication for localhost connections - # This fixes the "password authentication failed" error - if [ -d "${PGDATA}" ]; then - echo "local all onlyoffice trust" > "${PGDATA}/pg_hba.conf" - echo "local all all peer" >> "${PGDATA}/pg_hba.conf" - echo "host all all 127.0.0.1/32 trust" >> "${PGDATA}/pg_hba.conf" - echo "host all all ::1/128 trust" >> "${PGDATA}/pg_hba.conf" + # Check standard Ubuntu location first, then data directory + PG_CONF_FILE="/etc/postgresql/${PG_VERSION:-16}/main/pg_hba.conf" + if [ ! -f "$PG_CONF_FILE" ]; then + PG_CONF_FILE="${PGDATA}/pg_hba.conf" + fi + + if [ -f "$PG_CONF_FILE" ]; then + echo "Found pg_hba.conf at: $PG_CONF_FILE" + # Backup original + cp "$PG_CONF_FILE" "${PG_CONF_FILE}.bak" + # Overwrite with trust settings + echo "local all onlyoffice trust" > "$PG_CONF_FILE" + echo "local all all peer" >> "$PG_CONF_FILE" + echo "host all all 127.0.0.1/32 trust" >> "$PG_CONF_FILE" + echo "host all all ::1/128 trust" >> "$PG_CONF_FILE" + chown postgres:postgres "$PG_CONF_FILE" + else + echo "WARNING: pg_hba.conf not found!" fi LOCAL_SERVICES+=("postgresql")