Restart Sonar when web process dies


I am using SonarQube version 8.6.0.

My servers are hosted on AWS and configured to turn-off at 7:00PM and turn-on again at 08:00AM. The problem is the sonar database is in a RDS and it takes longer to startup than the EC2 machine. In the web.log I can see:

2021.01.04 11:23:25 INFO  web[][o.sonar.db.Database] Create JDBC data source for jdbc:postgresql://
2021.01.04 11:23:35 ERROR web[][o.s.s.p.PlatformImpl] Web server startup failed
java.lang.IllegalStateException: Fail to connect to database
Caused by: connect timed out

It timed out because the database server was still starting.

The last of the web.log are:

2021.01.04 11:23:35 INFO  web[][o.s.s.a.EmbeddedTomcat] HTTP connector enabled on port 9000
2021.01.04 11:23:35 INFO  web[][o.s.p.ProcessEntryPoint] Hard stopping process

The last lines of the sonar.log are:

2021.01.04 11:23:06 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2021.01.04 11:23:22 INFO  app[][o.s.a.SchedulerImpl] Process[es] is up
2021.01.04 11:23:22 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[[key='web', ipcIndex=2, logFilenamePrefix=web]] from [/opt/sonarqube-]: /usr/lib/jvm/java-11-openjdk- -Djava.awt.headless=true -Dfile.encoding=UTF-8 -XX:-OmitStackTraceInFastThrow --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/ --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Dhttp.nonProxyHosts=localhost|127.*|[::1] -cp ./lib/common/*:/opt/sonarqube- /opt/sonarqube-

I am running sonar with the SystemD, here is my sonarqube.service file:

Description=SonarQube service

ExecStart=/bin/nohup /etc/alternatives/jre_11/bin/java -Xms32m -Xmx32m -jar /opt/sonarqube/lib/sonar-application-


The problem is that the web process is not starting but the main process is still running and systemd is not restarting sonar.
Is there a way to stop the main process if the web fails to start? This way the process would keep restarting and, eventually whe database would be operational and it would stop restarting.

Thank you