SonarQube 7.5 Community Edition service stopping after few seconds the service was started


(JV Ortiz) #1

Hi,

Just would like to seek help on how will my downloaded SonarQube 7.5 Community Edition will run on the RHEL 7 server. Currently SonarQube service is stopping after few seconds the service was started, I have noticed on es.log that the embedded elasticsearch cannot run as root. On the script, I have set it to run as user sonar and modified sonar.properties but still the service won’t proceed on running. I have provided the logs and configuration below for reference.

PROD [root@psphvx019 ~]# service sonar start
Starting SonarQube...
Started SonarQube.
PROD [root@psphvx019 ~]# service sonar status
SonarQube is not running.

PROD [root@psphvx019 ~]# cat /opt/sonarqube/logs/sonar.log | tail -50
        at org.sonar.process.FileUtils2.deleteDirectory(FileUtils2.java:112)
        at org.sonar.application.AppFileSystem$CleanTempDirFileVisitor.visitFile(AppFileSystem.java:117)
        at org.sonar.application.AppFileSystem$CleanTempDirFileVisitor.visitFile(AppFileSystem.java:101)
        at java.nio.file.Files.walkFileTree(Files.java:2670)
        at org.sonar.application.AppFileSystem.createOrCleanTempDirectory(AppFileSystem.java:96)
        at org.sonar.application.AppFileSystem.reset(AppFileSystem.java:62)
        at org.sonar.application.App.start(App.java:55)
        at org.sonar.application.App.main(App.java:78)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
        at java.lang.Thread.run(Thread.java:748)
<-- Wrapper Stopped
--> Wrapper Started as Daemon
Launching a JVM...
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
  Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.

2018.12.28 11:36:26 INFO  app[ ][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp

WrapperSimpleApp: Encountered an error running main: java.nio.file.AccessDeniedException: /opt/sonarqube/temp/conf/es/log4j2.properties
java.nio.file.AccessDeniedException: /opt/sonarqube/temp/conf/es/log4j2.properties
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
        at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:244)
        at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
        at java.nio.file.Files.delete(Files.java:1126)
        at org.sonar.process.FileUtils2$DeleteRecursivelyFileVisitor.visitFile(FileUtils2.java:186)
        at org.sonar.process.FileUtils2$DeleteRecursivelyFileVisitor.visitFile(FileUtils2.java:181)
        at java.nio.file.Files.walkFileTree(Files.java:2670)
        at java.nio.file.Files.walkFileTree(Files.java:2742)
        at org.sonar.process.FileUtils2.deleteDirectoryImpl(FileUtils2.java:143)
        at org.sonar.process.FileUtils2.deleteDirectory(FileUtils2.java:112)
        at org.sonar.application.AppFileSystem$CleanTempDirFileVisitor.visitFile(AppFileSystem.java:117)
        at org.sonar.application.AppFileSystem$CleanTempDirFileVisitor.visitFile(AppFileSystem.java:101)
        at java.nio.file.Files.walkFileTree(Files.java:2670)
        at org.sonar.application.AppFileSystem.createOrCleanTempDirectory(AppFileSystem.java:96)
        at org.sonar.application.AppFileSystem.reset(AppFileSystem.java:62)
        at org.sonar.application.App.start(App.java:55)
        at org.sonar.application.App.main(App.java:78)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
        at java.lang.Thread.run(Thread.java:748)
<-- Wrapper Stopped

PROD [root@psphvx019 ~]# cat /opt/sonarqube/temp/conf/es/log4j2.properties
#log4j2 properties file for ES bundled in SonarQube
#Thu Dec 27 12:53:27 PHT 2018
appender.file_es.strategy.action.condition.glob=es*
rootLogger.appenderRef.file_es.ref=file_es
appender.file_es.strategy.action.condition.nested_condition.type=IfAccumulatedFileCount
appender.file_es.policies.time.modulate=true
appender.file_es.name=file_es
appender.file_es.strategy.action.maxDepth=1
appender.file_es.policies.time.interval=1
appender.file_es.strategy.action.condition.type=IfFileName
appender.file_es.type=RollingFile
appender.file_es.strategy.fileIndex=nomax
appender.file_es.fileName=/opt/sonarqube/logs/es.log
appender.file_es.strategy.action.condition.nested_condition.exceeds=7
appender.file_es.filePattern=/opt/sonarqube/logs/es.%d{yyyy-MM-dd}.log
appender.file_es.layout.type=PatternLayout
appender.file_es.policies.time.type=TimeBasedTriggeringPolicy
status=ERROR
rootLogger.level=INFO
appender.file_es.layout.pattern=%d{yyyy.MM.dd HH\:mm\:ss} %-5level es[][%logger{1.}] %msg%n
appender.file_es.strategy.action.type=Delete
appender.file_es.strategy.action.basepath=/opt/sonarqube/logs
appender.file_es.strategy.type=DefaultRolloverStrategy
appender.file_es.policies.type=Policies

PROD [root@psphvx019 ~]# cat /opt/sonarqube/bin/linux-x86-64/sonar.sh | grep sonar
RUN_AS_USER=sonar

PROD [root@psphvx019 ~]# ll -d /opt/sonarqube
drwxr-xr-x 11 sonar sonar 4096 Dec 18 10:03 /opt/sonarqube

PROD [root@psphvx019 ~]# ls -lrt /opt/sonarqube
total 44
drwxr-xr-x 2 sonar sonar 4096 Dec 18 09:58 data
-rw-r--r-- 1 sonar sonar 7651 Dec 18 09:58 COPYING
drwxr-xr-x 8 sonar sonar 4096 Dec 18 09:58 bin
drwxr-xr-x 4 sonar sonar 4096 Dec 18 09:58 extensions
drwxr-xr-x 6 sonar sonar 4096 Dec 18 10:03 lib
drwxr-xr-x 9 sonar sonar 4096 Dec 18 10:03 web
drwxr-xr-x 2 sonar sonar 4096 Dec 27 10:07 logs
drwxr-xr-x 3 sonar sonar 4096 Dec 27 12:53 temp
drwxr-xr-x 8 sonar sonar 4096 Dec 27 12:56 elasticsearch
drwxr-xr-x 2 sonar sonar 4096 Dec 28 11:34 conf

PROD [root@psphvx019 ~]# cat /opt/sonarqube/logs/es.log | tail -26
java.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]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) [elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) [elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) [elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) [elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) [elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.6.3.jar:5.6.3]
2018.12.27 12:53:28 WARN  es[][o.e.b.ElasticsearchUncaughtExceptionHandler] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) ~[elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) ~[elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.6.3.jar:5.6.3]
Caused by: java.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]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) ~[elasticsearch-5.6.3.jar:5.6.3]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) ~[elasticsearch-5.6.3.jar:5.6.3]
        ... 6 more

PROD [root@psphvx019 ~]# cat /opt/sonarqube/conf/sonar.properties | egrep 'sonar.web.javaOpts|sonar.web.javaAdditionalOpts|sonar.ce.javaOpts|sonar.ce.javaAdditionalOpts|sonar.search.javaOpts|sonar.search.javaAdditionalOpts'
sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
#sonar.web.javaAdditionalOpts=
sonar.ce.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
#sonar.ce.javaAdditionalOpts=
sonar.search.javaOpts=-Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError
sonar.search.javaAdditionalOpts=-Dbootstrap.system_call_filter=false

PROD [root@psphvx019 ~]# cat /opt/sonarqube/elasticsearch/config/jvm.options | grep -v "#"
-Xms2g
-Xmx2g
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
-XX:+AlwaysPreTouch
-server
-Xss1m
-Djava.awt.headless=true
-Dfile.encoding=UTF-8
-Djna.nosys=true
-Djdk.io.permissionsUseCanonicalPath=true
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
-Dlog4j.skipJansi=true
-XX:+HeapDumpOnOutOfMemoryError

(G Ann Campbell) #2

Hi,

Here’s your problem:

SonarQube starts an Elasticsearch process, and Elasticsearch refuses to run as root. You’ll need to set your service up to run as a different user.

 
Ann


(JV Ortiz) #3

Hi Ann,

I have already set it to run as sonar user on sonar script and created sonar account.


(JV Ortiz) #4

Finally figure out what I’m missing, SonarQube service is now running.


(Nicolas Bontoux) #5

It would be interesting that you share what the actual problem was, and how you solved it, so that other members of this community can benefit from your findings in case they encounter similar problems!