Running SonarQube as a Service on Windows

With reference to Operating the Server | SonarQube Docs
I tried to create a Sonarqube window service with following command but it doesn’t work.

sc create SonarQube binPath= “”%SONARQUBE_HOME%\bin\windows-x86-64\wrapper.exe" -s %SONARQUBE_HOME%\conf\wrapper.conf"

I noticed if I create the service without the conf file argument, service is created successfully.
When I check the sc create parameter, doesn’t seem to have “-s” to take in config file.

Here’s what I got in sc create:
NOTE: The option name includes the equal sign.
A space is required between the equal sign and the value.
type= <own|share|interact|kernel|filesys|rec|userown|usershare>
(default = own)
start= <boot|system|auto|demand|disabled|delayed-auto>
(default = demand)
error= <normal|severe|critical|ignore>
(default = normal)
binPath= <BinaryPathName to the .exe file>
group=
tag= <yes|no>
depend= <Dependencies(separated by / (forward slash))>
obj= <AccountName|ObjectName>
(default = LocalSystem)
DisplayName=
password=

1 Like

Hello @yapeutat,

Did you properly escape the \" signs in the command provided in the documentation ? I believe that xould well be the root cause of your problem. The value for the binPath parameter must be the full string "%SONARQUBE_HOME%\bin\windows-x86-64\wrapper.exe" -s "%SONARQUBE_HOME%\conf\wrapper.conf"

So you must pass binPath= "\"%SONARQUBE_HOME%\bin\windows-x86-64\wrapper.exe\" -s \"%SONARQUBE_HOME%\conf\wrapper.conf\""

(To this respect there is a slight error in the docs because the path of the config file is not quoted and if %SONARQUBE_HOME% has a space, it will fail, hence my more failsafe cmd suggestion:

sc create SonarQube binPath= "\"%SONARQUBE_HOME%\bin\windows-x86-64\wrapper.exe\" -s \"%SONARQUBE_HOME%\conf\wrapper.conf\""`

Also to start/stop the service, the doc has a typo. It should be:

"%SONARQUBE_HOME%/bin/windows-x86-64/StartNTService.bat"
"%SONARQUBE_HOME%/bin/windows-x86-64/StopNTService.bat"

Olivier

1 Like

Thanks Olivier!

sc create SonarQube binPath= “”%SONARQUBE_HOME%\bin\windows-x86-64\wrapper.exe" -s “%SONARQUBE_HOME%\conf\wrapper.conf”"`

This works and service is created.

Service is created but the when I tried to start the service, below error is shown.
The system cannot find the path specified.

Same goes for stopping the service.

I used the command as below:
“%SONARQUBE_HOME%/bin/windows-x86-64/StartNTService.bat”
“%SONARQUBE_HOME%/bin/windows-x86-64/StopNTService.bat”

Hello,

Do you have an environment variable set with the real path of the SonarQube installation ? The %SONARQUBE_HOME% env variable must best set to something meaningful. Do you confirm it is set properly ? Alternatively you can replace this env variable by the hardcoded path of your SonarQube installation like, if you SonarQube is installed in C:\sonarqube, the below:

:: Stop and delete the existing service
sc stop SonarQube
sc delete SonarQube
:: Reinstall with hardcoded path
sc create SonarQube binPath= "\"C:\sonarqube\bin\windows-x86-64\wrapper.exe\" -s \"C:\sonarqube\conf\wrapper.conf\""
:: Start/Stop service
"C:\sonarqube\bin\windows-x86-64\StartNTService.bat"
"C:\sonarqube\bin\windows-x86-64\StopNTService.bat"

:: Note, the StartNTService.bat / StopNTService.bat batch scripts can probably also be replaced by the native sc commands below
sc start SonarQube
sc stop SonarQube

Hi,

I tried with %SONARQUBE_HOME% and also with full hardcoded path, both also display the same error message: The service did not respond to the start or control request in a timely fashion.

Same thing with using native sc command, same error message appears when I tried to start the service.

This must be a problem on your Windows machine, we don’t do anything fancy, and simply leverage the Windows service capabilities.
I would suggest that for the time being you first start your SonarQube from the command line (%SONARQUBE_HOME%\bin\windows-x86-64\StartSonar.bat) to have your SonarQube up and running and then check with Microsoft why a service would not start.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.