How to install Solr as a Windows Service

With the latest release of Sitecore 9, there is the need to have Solr running also for a single server installation. This is largely thanks to the new xConnect layer that uses either Solr or Azure Search. If you find yourself in the need to install Solr on Windows and run it as a service, let me share with you some of my learnings from this journey.

Apache Solr is an open-source search engine built on Java and largely aimed at running as a Linux daemon – which is also very well described in the documentation linked in pretty much every Sitecore installation manual. Being a Java application it is also possible to run Solr on Windows, but there is no “out of the box” way to install Solr as a Windows service (remembering the easy installation of MongoDB as a Windows service…).

Get the tools

Although you can totally automate the process, I am describing below – using for instance Jeremy Davis‘ PowerShell scripted  Low-Effort Solr Installs  approach, my goal is to describe every step of a manual installation and its cautions.

In order to get Solr running as a Windows service we need a little help. While the name might not inspire confidence, NSSM (Non Sucking Service Manager) is a tool that allows for registering Solr as a Windows service.

My goal was installing the Solr service on Windows Server 2016 64 bit. Therefore, I grabbed the latest pre-release of NSSM 2.24-101-g897c7ad and unzipped it on my local disk. There is no installation needed.

Get it going

In the NSSM folder you can find the 32 and 64 bit executables. I used the 64 bit one. My NSSM folder was placed in C:\NSSM and my Solr server was installed on C:\Solr.

To install Solr as Windows service, open a new command line in the folder with the NSSM executable of your choice and then type:

A configuration window will appear, so you should fill the Path to  the Solr.cmd file. In my case this is C:\Solr\bin\solr.cmd . The Startup directory gets filled automatically, so you can keep it. In the Arguments field you should write the parameters to start the instance. In my case it is start -f . Solr selects automatically the port 8983, so if that is what you are looking for, there is no need to specify it. If you want to specify the port, you can add it to the parameters: s start -f -p 8983 .

The window of NSSM then looks like this:

NSSM Solr Service Install

Hit “Install service” and the service is ready to be started (either from the task manager, from the services manager or from the command line.

The -f parameter

I learned the hard way, that the -f parameter is critical to the success of the operation. While everything will be installed correctly and run even without the parameter, a little counter-intuitively, you should always start the service in foreground. This is because, without the -f parameter, Solr will start in the background. And while you will successfully check that you can open the Solr admin page, whenever you need to restart the service (e.g. while Sitecore install script is running and trying to restart Solr), the service in the background will still be running and it will try to get another Solr up. This will ultimately conflict on the port, which is still the same and you will get an error message. I also encountered strange behaviors like after the stopping and completely removing the Solr service, I was still able to work with Solr just fine, as it was still running somewhere.

The -f parameter allows for the service to always restart the currently running Solr process, without trying to spin a new one up. Ultimately, this is the expected behavior.

One thought on “How to install Solr as a Windows Service”

  1. Did you not encounter problems with NSSM not being able to stop or restart Solr due to the “Terminate Batch Job (Y/N)” prompt from bin/solr.cmd when NSSM sends a CTRL-C to the process? I’ve been trying to work around that in various ways but still not quite there.

Leave a Reply

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