You start SonarQube and the service seems to come up. You see TCP port connection activity. It does not stay up long enough to log in.
You have SonarQube installed on a Linux server. SonarQube starts, but it does not remain running because it dies out. It stops running after 30 seconds of being started.
In /opt/sonarqube/es.log you see a message like this: "2018.05.23 17:01:53 WARN es[o.e.b.ElasticsearchUncaughtExceptionHandler] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root"
In /opt/sonarqube/sonar.log you see a message like this:
"WrapperSimpleApp: Encountered an error running main: java.nio.file.AccessDeniedException: /opt/sonarqube/temp/conf/es/log4j2.properties
You did not start sonar as a root user. How do you get the SonarQube service to remain on when it keeps stopping for no reason?
Possible solution #1
In the sonar.properties file are the credentials to the database correct? An invalid username and password could produce the behavior you are experiencing.
Possible solution #2
Go to the logs directory in the sonarqube directory. There may be clues there.
Possible solution #3
1. Run this command: sudo rm -rf /opt/sonarqube/temp
2. Run this command, but see the notes below to customize it for your server:
sudo chown -R sonar:sonargroup /opt/sonarqube
# replace the first "sonar" with the user that will start the service;
# replace the sonargroup in the above with the group of the user that will start the service. If you do not know what this is but you do know the user, log into the Linux server as the user and run the "groups" command. The result will be some of the groups the user is in.
3. Reboot the server.
4. Start the Sonar service as normal. A normal way would be to log in as the "sonar" user and run the sonar.sh script like this:
Another way would be to run these commands:
sudo systemctl start sonar
sudo systemctl enable sonar
sudo systemctl status sonar