Race condition on system boot (database availability)

Openfire is starting before the local database server on system boot. Unfortunately it attempt to reconnect too quickly and gives up too soon and just sits there with an exception saying it could not connect. I usually have to manually restart the service.

==> /var/log/openfire/openfire.log <==
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [?:1.8.0_402]
        at java.lang.Class.newInstance(Class.java:442) [?:1.8.0_402]
        at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:4.7.5]
        at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:4.7.5]
Caused by: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 retries. The exception from the last attempt is as follows: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-4.7.5.jar:4.7.5]
        at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1052) ~[xmppserver-4.7.5.jar:4.7.5]
        ... 9 more

Looks like it attempts it multiple times per second for only a few seconds before ‘giving up’

2024.03.14 05:10:48 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 0 out of 10).
2024.03.14 05:10:48 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 1 out of 10).
2024.03.14 05:10:48 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 2 out of 10).
2024.03.14 05:10:49 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 3 out of 10).
2024.03.14 05:10:49 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 4 out of 10).
2024.03.14 05:10:49 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 5 out of 10).
2024.03.14 05:10:49 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 6 out of 10).
2024.03.14 05:10:50 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 7 out of 10).
2024.03.14 05:10:50 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 8 out of 10).
2024.03.14 05:10:50 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 9 out of 10).
2024.03.14 05:10:50 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 10 out of 10).
2024.03.14 05:10:51 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 0 out of 10).
2024.03.14 05:10:51 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 1 out of 10).
2024.03.14 05:10:52 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 2 out of 10).
2024.03.14 05:10:52 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 3 out of 10).
2024.03.14 05:10:52 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 4 out of 10).
2024.03.14 05:10:52 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 5 out of 10).
2024.03.14 05:10:53 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 6 out of 10).
2024.03.14 05:10:53 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 7 out of 10).
2024.03.14 05:10:53 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 8 out of 10).
2024.03.14 05:10:53 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 9 out of 10).
2024.03.14 05:10:54 INFO  [main]: org.jivesoftware.database.DbConnectionManager - Unable to get a connection from the database pool (attempt 10 out of 10).

How can I increase the wait time between retries?

I would suggest to not increase the ‘wait-time’ between retries, but to configure your system in such a way that the database starts sooner than Openfire. There are various ways to do that. Please refer to the documentation of your operating system to find a way that’s most suitable for your system.