Force-stop does not use Java command from wrapper.conf

Versions

  • SonarQube: 8.8 (build 42792)
  • OS: CentOS release 6.10 (Final)
  • Bash: 4.1.2(2)-release

Error

When Java is not on the PATH but is set in wrapper.conf, using force-stop results in an error:

$ /sonarqube/8.8/bin/linux-x86-64/sonar.sh force-stop
Force stopping SonarQube...
/sonarqube/8.8/bin/linux-x86-64/sonar.sh: line 526: java: command not found

SonarQube is not stopped (and the script waits forever for SonarQube to stop).

Steps to Reproduce

  1. Run SonarQube
  2. Without adding Java to the PATH, attempt to force stop SonarQube

Potential Workaround

Adding Java to PATH fixes this error.

Potential Issue/Fix

It seems like the code in sonar.sh that reads the Java command from the wrapper.conf is incorrect. The code correctly finds the Java command, but sets CMDJAVA from inside a subshell (due to the pipe). Thus, CMDJAVA isn’t set in the main shell and always points to "java".

I was able to get force-stop working by modifying the script to:

for line in $(grep "wrapper.java.command=" "$WRAPPER_CONF" | grep -v "^#"); do
  CMDJAVA="${line#*=}"
  break
done

It may also be helpful to add some type of exception handling around the call to org.sonar.application.Shutdowner.