Elasticsearch not starting maybe due to java memory

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension)
    SonarQube latest community build

  • how is SonarQube deployed: zip, Docker, Helm

  • what are you trying to achieve

  • what have you tried so far to achieve this

Trying to get sonar working on AWS in Docker container
Getting some sort of memory error when starting up SonarQube community edition on AWS
Tried changing various environment variables to no affect

This is the Dockerfile error and spot in the code I think the problem is

----------------------------------------Dockerfile-------------------------------------
services:
  sonarqube:
    image: sonarqube:latest
    hostname: sonarqube
    container_name: sonarqube
    read_only: true
    depends_on:
      db:
        condition: service_healthy
    environment:
      SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
      SONAR_JDBC_USERNAME: sonar
      SONAR_JDBC_PASSWORD: sonar
#      JAVA_TOOL_OPTIONS: "-Xms750m -Xmx750m"
      ES_JAVA_OPTS: -Xms750m -Xmx750m
#      SONAR_ES_JAVA_OPTS: "-Xms750m -Xmx750m"
      SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: true
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
      - sonarqube_temp:/opt/sonarqube/temp
    mem_limit: 2g
    ports:
      - "9000:9000"
    networks:
      - sonar-network
 
  db:
    image: postgres:latest
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5
    hostname: db
    container_name: postgresql
    environment:
      POSTGRES_USER: sonar
      POSTGRES_PASSWORD: sonar
      POSTGRES_DB: sonar
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data
    networks:
      - sonar-network

volumes:
  sonarqube_data:
  sonarqube_temp:
  sonarqube_extensions:
  sonarqube_logs:
  postgresql:
  postgresql_data:

networks:
  sonar-network:
    driver: bridge
    enable_ipv6: false
----------------------------------------error------------------------------------
sonarqube   | 2025.02.04 14:57:08 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/opt/sonarqube/elasticsearch]: /opt/java/openjdk/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=./bin/elasticsearch -Dcli.libs=lib/tools/server-cli -Des.path.home=/opt/sonarqube/elasticsearch -Des.path.conf=/opt/sonarqube/temp/conf/es -Des.distribution.type=tar -cp /opt/sonarqube/elasticsearch/lib/*:/opt/sonarqube/elasticsearch/lib/cli-launcher/* org.elasticsearch.launcher.CliToolLauncher
sonarqube   | 2025.02.04 14:57:08 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
sonarqube   | Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
sonarqube   | java.lang.RuntimeException: starting java failed with [137]
sonarqube   | output:
sonarqube   | 
sonarqube   | error:
sonarqube   | 
sonarqube   | 	at org.elasticsearch.server.cli.JvmOption.flagsFinal(JvmOption.java:121)
sonarqube   | 	at org.elasticsearch.server.cli.JvmOption.findFinalOptions(JvmOption.java:88)
sonarqube   | 	at org.elasticsearch.server.cli.MachineDependentHeap.determineHeapSettings(MachineDependentHeap.java:56)
sonarqube   | 	at org.elasticsearch.server.cli.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:146)
sonarqube   | 	at org.elasticsearch.server.cli.JvmOptionsParser.determineJvmOptions(JvmOptionsParser.java:98)
sonarqube   | 	at org.elasticsearch.server.cli.ServerCli.startServer(ServerCli.java:268)
sonarqube   | 	at org.elasticsearch.server.cli.ServerCli.execute(ServerCli.java:111)
sonarqube   | 	at org.elasticsearch.common.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:55)
sonarqube   | 	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:95)
sonarqube   | 	at org.elasticsearch.cli.Command.main(Command.java:52)
sonarqube   | 	at org.elasticsearch.launcher.CliToolLauncher.main(CliToolLauncher.java:65)
sonarqube   | 2025.02.04 14:57:13 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 70
sonarqube   | 2025.02.04 14:57:13 INFO  app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
sonarqube   | 2025.02.04 14:57:13 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
--------------------spot in server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java line 96 -----------------------------------------
 @Test
  public void constructor_logs_warning_if_env_variable_ES_JAVA_OPTS_is_set() {
    when(system2.getenv("ES_JAVA_OPTS")).thenReturn("xyz");
    attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class);

    new CommandFactoryImpl(new Props(new Properties()), tempDir, system2);

    assertThat(listAppender.getLogs())
      .extracting(ILoggingEvent::getMessage)
      .containsOnly(
        "ES_JAVA_OPTS is defined but will be ignored. " +
          "Use properties sonar.search.javaOpts and/or sonar.search.javaAdditionalOpts in sonar.properties to change SQ JVM processes options");
  }


Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi,

Welcome to the community!

Do you know where this jar is coming from?

Can you remove it and try again?

 
Ann

The sonarqube container is coming from the latest Docker location.

Hi,

Okay. What shows up in your es.log?

 
Thx,
Ann

The container goes away after the failure and I cannot get to the logs. Where is it located?

Hi,

Where you put it:

 
HTH,
Ann

Thanks for helping…
There is no es.log in that location, only the sonar.log which contains stuff similar to the above.

I can get it working on my home machine, but not AWS.

Hi,

On your home machine do you get this in the logs?

 
Thx,
Ann

Going back to what you observed first :slight_smile:
I am not getting that my home machine.
Can I get around this by setting CLASSPATH to just the ones needed or supplied by SonarQube?

If I knew where the “Standard Commons Logging” exists, I could remove it?

Hi,

As you pointed out, you’re using our Docker file, so the classpath should start out at what it needs to be. I’m going to flag this for the team.

 
Ann

Thanks for escalating it.

I am working on trying to figure out where the logs are on my local machine, but I highly suspect it is that logging code conflict and where I pointed to in the code base. I just do not want to contribute to the code without knowing what is going on there.

1 Like

I have the logs from my local machine and the same error (warning) does not exist. There is something different from the Ubuntu and AWS Linux on AWS which causes this conflict in Java logging code. There must be a way to use an environment variable to modify the CLASSPATH.

1 Like

Happy Feb 11th :slight_smile:

OK … I had a good idea… I exported the AWS machine and imported it to my local VMWare host.

It worked even though it put out the same warning message referring to sonarqube | Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts

I still think it is some sort of memory limitation in the elasticsearch process.

I still want to get it working in AWS and suspect it is something to do with the “micro” instance of AWS and I don’t want to pay for a bigger one. it should work in the 8MB memory machine.

1 Like

This is not an issue. It needed more memory. Something in the server notes for starting says it need 1like 16GB memory.

1 Like