Migrate SonarQube from Tomcat to a Windows service

SonarQubeService

As I have already mentioned, SonarQube will soon be no longer available for Tomcat, but only as a Windows service. That means that I will have to migrate my platform SonarQube / Jenkins.

This brings some questions: will I loose my settings? Will I loose my analysis? SonarQube uses a database to store the results of the analysis, so we can expect to keep them and their history.

But what about my SonarQube configuration? Will I have to reinstall plugins? Damn, where did I put the license keys for these plugins? And my Quality Profiles? Are they stored in the database or in a file?

In what order should I proceed: first migrate Jenkins then check if Jenkins is still able to recognize my SonarQube installation and continue to work on existing projects? In fact, I will start by migrating SonarQube, because it is far simpler than Jenkins.

We then have the opportunity to continue with this last one and install it as a service, so we will finally be able to get rid of Tomcat.

Migrate SonarQube to a Windows service

Objectives

Note that I will migrate my current version 3.5.1 of SonarQube. There is a newer version 3.7 … at the time I am writing this post. It changes very quickly, the SonarSource team is highly productive. This latest 3.7 version has many new features, and it will be the subject of future posts.

This is also an opportunity to check how to perform an upgrade of version of SonarQube as a service. If this topic interests you, we have seen how to perform such an upgrade there: Upgrade Sonar.

I will also dedicate this post to a migration of the SonarQube as a Windows service, and ensure that I can continue to work with my existing repository: my dashboard, my analysis, my configurations, etc.. We will see in the next post the changes to make in my current Jenkins (under Tomcat) to work with my new SonarQube installation.

Documentation

Like any (good) IT specialist, I never read documentations, and especially not those about installation. I find it quite unnatural if a software does not know how to install itself (you know: ‘Next’, ‘Next’, ‘Next’, etc.) and requires to first read an installation guide. But well, here is the link to the SonarSource website: http://docs.codehaus.org/display/SONAR/Running+SonarQube+as+a+Service+on+Windows.

Well, it looks super simple:

Sonar_InstallWinService

Installation

I will first stop Tomcat, to be sure that I will not be working with my current SonarQube installation.

Stop_Tomcat

Then I open a DOS windows and go to the directory of installation of SonarQube.

Sonar_Bin

My current SonarQube version is 3.5.1. In the foleer ‘\sonar-3.5.1\bin’, I can find two sub-directories ‘windows-x86-32’ and ‘windows-x86-64’, this last one for an installation with a Windows 64 bits.

Sonar_InstallWinService2

I won’t go into details of what this batch program. does. We’ll just follow the recommendation of the documentation and run this program as an Administrator.

It’s very fast. I note the appearance of the Sonar service in the Services window.

Sonar_Service

I can launch this service, either with a ‘Start’ from this service, either executing the corresponding file in the ‘bin’ directory of SonarQube, from my DOS window.

sonar_Runservice1

But this will bring the following error message:

Sonar_ServiceLaunchError

Same if I try to start the SonarQube service:

Sonar_ServiceLaunchError2

Sonar_ServiceProp1

Now, if we open the service Properties (right click on the service to get the menus)…

 

 

 

 

…and goes on the tab ‘Log On’.

Sonar_ServiceProp2

Check the box ‘This account’ and then the button ‘Browse’ :

Sonar_ServiceProp3

In the following windows, click the button ‘Advanced’.

Sonar_ServiceProp4a

Then ‘Find Now’ in order to list the users who can connect (Log On) to launch this service.

Sonar_ServiceProp4

I will select the Windows user I use to log on my laptop:

Sonar_ServiceProp5

‘OK’ to validate. Notice that my Window user is prefixed with the ID of my machine (JPFPC).

Sonar_ServiceProp6

‘OK’ again to get back to the ‘Log On’ tab, where I can enter the password corresponding to my user. ‘Apply’ then ‘OK’ to close the Properties window.

Now we can start again the service and … Yes, it works ! The error message has disappeared and the service displays a ‘Started’ status.

Validation

SonarQubeURL

Your SonarQube dashboard- as a Windows service – is available at the url localhost:9000. Enter it in your favorite browser, and you will see your SonarQube portal as it was the last one you’ve been consulting it.

You can check that your previous analysis appear correctly, your custom Quality Profiles are present, your plugins are also there, and active (no need to re-enter the licenses). Your entire SonarQube configuration under Tomcat and your projects, well your whole repository, is fully available and ready for use.

We still have to perform an analysis from our current Jenkins under Tomcat.

This we will see in the next post. In the meantime, have a good week.

One thought on “Migrate SonarQube from Tomcat to a Windows service

  1. Mika

    Hi,

    Thanks for this article. It helped me to fix it and now I am able to run it as system user.

    To get Sonar service to run as system all you need to do is create one new folder named “Temp” in C:\Windows\System32\config\systemprofile\AppData\Local\

    Br, Mika

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *