Can't run Sonar Server caused by Elasticsearch cannot running as root Can't run Sonar Server caused by Elasticsearch cannot running as root elasticsearch elasticsearch

Can't run Sonar Server caused by Elasticsearch cannot running as root


SonarSource has upgraded the Elasticsearch tool used as a part of the latest SonarQube LTS version. As a result SonarQube cannot be run as a root. See this blog and the SonarQube 6.6 upgrade notes and this SO question.


Change the root access to the sonar file. Try running in normal user access.

chown <another user>:<user group> sonar.sh


I was facing the same issue and spend good amount of time before getting the solution.

Error was same as

2017.12.09 18:05:14 ERROR es[][o.e.b.Bootstrap] Exceptionjava.lang.RuntimeException: can not run elasticsearch as root    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.6.3.jar:5.6.3]    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:195) ~[elasticsearch-5.6.3.jar:5.6.3]

SolutionCreate a ‘sonar’ user using adduser command //I was using linux systemchown -R sonar sonar-install-folder/Edit the sonar.sh file sonar-install-folder/bin/linux-x86-6 in start script and change the #RUN_AS_USER to be RUN_AS_USER=sonar

And then use below commands

./sonar.sh stop

Gracefully stopping SonarQube...SonarQube was not running.

./sonar.sh start

Starting SonarQube...Started SonarQube.

./sonar.sh status

SonarQube is running (22100).

So, basically elastic search doesnt require to be run by root user. By default the RUN_AS_USER was commented in the startup script which was picking my current user which was root, and then some linux permission rules come into picture due to which elasticsearch process was not getting up and which was causing sonar process to go down as well.

It was evident from sonar.log

[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]2020.05.08 06:36:36 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [es]: 782020.05.08 06:36:36 INFO  app[][o.s.a.SchedulerImpl] Process[es] is stopped2020.05.08 06:36:36 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped