简体   繁体   中英

Keycloak retry database connection during startup

I have Keycloak on one server configured to connect to a remote PostgreSQL database, both the database and the Keycloak server start at the same time in the morning but the database takes a little more time before it's available which prevents the Keycloak service from starting:

WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 63) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection

I tried adding the following lines to standalone.xml but it only seems to prevent Keycloak from crashing if it's already started and the database reboots:

<validation>
  <check-valid-connection-sql>select 1</check-valid-connection-sql>
  <validate-on-match>false</validate-on-match>
  <background-validation>true</background-validation>
  <background-validation-millis>15000</background-validation-millis>
</validation>

If anyone is looking for a solution and is using systemd , I ended up adding these two lines to my keycloak.service file in the [Service] block:

Restart=always
RestartSec=5min

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM