Restart Sonar when web process dies

Hello,

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://db.sonarqube.hmledp.com.br/sonarqube
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: java.net.SocketTimeoutException: 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-8.6.0.39681]: /usr/lib/jvm/java-11-openjdk-11.0.7.10-4.amzn2.0.1.x86_64/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sonarqube-8.6.0.39681/temp -XX:-OmitStackTraceInFastThrow --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Dhttp.nonProxyHosts=localhost|127.*|[::1] -cp ./lib/common/*:/opt/sonarqube-8.6.0.39681/lib/jdbc/postgresql/postgresql-42.2.17.jar org.sonar.server.app.WebServer /opt/sonarqube-8.6.0.39681/temp/sq-process18431133089119317011properties

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

[Unit]
Description=SonarQube service
After=syslog.target network.target

[Service]
Type=simple
User=sonarqube
Group=sonarqube
PermissionsStartOnly=true
ExecStart=/bin/nohup /etc/alternatives/jre_11/bin/java -Xms32m -Xmx32m -Djava.net.preferIPv4Stack=true -jar /opt/sonarqube/lib/sonar-application-8.6.0.39681.jar
StandardOutput=syslog
LimitNOFILE=262144
LimitNPROC=8192
TimeoutStartSec=5
Restart=always
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

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