lifecycle: refresh PostgreSQL connection params on startup while testing connection (#10996)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L.
2024-08-20 20:22:03 +02:00
committed by GitHub
parent d54718c8d9
commit 5d33f3ccaa
+16 -4
View File
@@ -10,15 +10,20 @@ from redis.exceptions import RedisError
from authentik.lib.config import CONFIG, redis_url
CHECK_THRESHOLD = 30
def check_postgres():
attempt = 0
while True:
if attempt >= CHECK_THRESHOLD:
sysexit(1)
try:
conn = connect(
dbname=CONFIG.get("postgresql.name"),
user=CONFIG.get("postgresql.user"),
password=CONFIG.get("postgresql.password"),
host=CONFIG.get("postgresql.host"),
dbname=CONFIG.refresh("postgresql.name"),
user=CONFIG.refresh("postgresql.user"),
password=CONFIG.refresh("postgresql.password"),
host=CONFIG.refresh("postgresql.host"),
port=CONFIG.get_int("postgresql.port"),
sslmode=CONFIG.get("postgresql.sslmode"),
sslrootcert=CONFIG.get("postgresql.sslrootcert"),
@@ -30,12 +35,17 @@ def check_postgres():
except OperationalError as exc:
sleep(1)
CONFIG.log("info", f"PostgreSQL connection failed, retrying... ({exc})")
finally:
attempt += 1
CONFIG.log("info", "PostgreSQL connection successful")
def check_redis():
url = CONFIG.get("cache.url") or redis_url(CONFIG.get("redis.db"))
attempt = 0
while True:
if attempt >= CHECK_THRESHOLD:
sysexit(1)
try:
redis = Redis.from_url(url)
redis.ping()
@@ -43,6 +53,8 @@ def check_redis():
except RedisError as exc:
sleep(1)
CONFIG.log("info", f"Redis Connection failed, retrying... ({exc})")
finally:
attempt += 1
CONFIG.log("info", "Redis Connection successful")