Wednesday, May 2, 2012

Install Sonar on Windows as a Windows Service

This short tutorial shows how to setup Sonar as a Windows Service on Windows.

Step 1: Download Sonar from the Sonar download website.


Step 2: Unzip the .zip file and move the entire 'sonar-3.0' directory to 'C:\Program Files'.

Step 3: Double-click C:\Program Files\sonar-3.0\bin\windows-x86-64\StartSonar.bat to start Sonar. If your machine is 32-bit, run C:\Program Files\sonar-3.0\bin\windows-x86-32\StartSonar.bat instead.

Step 4: Verify it's running. Open up a browser and go to: http://localhost:9000/. You should see the following...


Step 5: Setup Sonar to start as a Windows Service. Double-click C:\Program Files\sonar-3.0\bin\windows-x86-64\InstallNTService.bat. If your machine is 32-bit, run C:\Program Files\sonar-3.0\bin\windows-x86-32\InstallNTService.bat instead.

Step 6: Restart the computer.

Step 7: Verify again that it's running. The Sonar Windows service should start Sonar when the machine boots up. Open up a browser and go to: http://localhost:9000/. For administration features, the Sonar default login/password is admin/admin.

One Small Issue

After restarting the computer and checking if Sonar was running, Sonar was not running. After some digging, I found that you can look in C:\Program Files\sonar-3.0\logs\sonar.log to debug Sonar. The following log messages hinted at the problem:

INFO | jvm 1 | 2012/05/02 12:55:26 | WrapperSimpleApp: Encountered an error running main: java.lang.IllegalStateException: Unable to create file in temporary directory, please check existence of it and permissions: C:\Windows\system32\config\systemprofile\AppData\Local\Temp\
INFO | jvm 1 | 2012/05/02 12:55:26 | java.lang.IllegalStateException: Unable to create file in temporary directory, please check existence of it and permissions: C:\Windows\system32\config\systemprofile\AppData\Local\Temp\
INFO | jvm 1 | 2012/05/02 12:55:26 | at org.sonar.application.StartServer.canCreateTemporaryFiles(StartServer.java:60)

Apparently, Sonar is trying to write to a temp file and Windows is not letting it. After all failed attemps to create the Temp folder manually and remove the write protection, I ended up solving the issue by manually configuring the Windows Service. The Sonar Windows Service's "user" was LocalSystem by default. I had to switch the service over to run under a regular user, and that fixed the issue.

Piece of Cake!!!

Relevant Links

Sonar on Wikipedia
sonarsource.org

16 comments:

Anonymous said...

Thanks. This saved me big time!

Michał Wróbel said...

Thanks for the hint with windows service and temp dir, you're my todays time saver! :D

Anonymous said...

Thanks. This hint helped me. But I also had to set the sonar directory rights to this user.

Anonymous said...

Thanks!!. Fixed my issue.

Anonymous said...

Very clear description - most helpful. I love the use of inset screenshots for clarity.

This is sooooo much more useful than the Sonar installation page.

Alexandro Velarde said...

I have post a blog to help people to Install and configure Sonar on Windows 7 for C# project in 10 minutes... check it out. It talks about running it as service as well.

http://sharedtolearn.blogspot.ca/2012/10/install-and-configure-sonar-on-windows.html

Tim Tapping said...

I was able to designate Network Service, clear the password fields and hit apply. started up rather smartly!

Tim Tapping said...

Thanks, good info. BTW, I was able to use Network Service as well. clear the PW fields and hit apply. good to go.

Robert Burkhall said...

Well, I discovered that the Temp folder didn't exist. Created it and the issue went away allowing the service account to work without using a user account.

Anonymous said...

You could also define where you want the temp folder to be e.g. -Djava.io.tmpdir=C:/Temp/. See here for more details.

Anand Nair said...

this was a blessing to know, thanks buddy

Alvaro Fernández González said...

Really helpful :)

admin said...

Thank you!! You saved me a lot of time with your advice!

Anonymous said...

+1

Anonymous said...

Thanks for the Hint. Could figure out the Issue.

The 'Temp' folder has to created at
C:\Windows\SysWOW64\config\systemprofile\AppData\Local

Serkan APUL said...

clearing sonar server temp folder fixed my problem

C:\sonarqube\temp