Setting up Apache Solr on Windows as a service

I had to set up Apache Solr 4 on Windows as a service using Jetty container. The following is the documentation on how to do it. I am not saying that this is the best way to get it to work. But it is one way that works and seems to be more recent and more comprehensive than the other approaches I found.

Initial setup

  1. Ensure Java version 1.6 or higher is present on the machine. If not, download it from http://www.java.com/ (Java 7 is actually also known as 1.7).
  2. Download latest Solr (here Solr 4.3.1) and unpack it somewhere.
  3. Create a directory where your Solr configuration and Jetty will live (e.g. C:\Services\SolrService, which we will refer to as <_SOLRDIR_>).
  4. If you don’t have Solr configuration defined yet, you can just copy Solr’s own example\solr directory to <_SOLRDIR_>, such that solr.xml is just inside <_SOLRDIR_> directory.
  5. Under the <_SOLRDIR_>, create subdirectory called jetty.
  6. Copy the following directories and the files into the jetty subdirectory from the Solr’s example directory:
    • contexts
    • etc
    • lib
    • logs
    • resources (Solr 4.3+)
    • webapps
    • start.jar
  7. From the command line in the jetty directory, run the Solr server to make sure it works:
    1. java -Dsolr.solr.home=.. -jar start.jar
    2. Ensure that Solr is accessible at: http://localhost:8983/solr/
    3. Stop the server (Ctrl-C)

Service setup for availability

  1. Download Apache Commons’ Daemon package for Windows (make sure to get the Windows package that includes .exe files).

  2. Copy platform-appropriate prunsrv.exe into the jetty directory and rename it to SolrService.exe - this is the actual Windows service executable.

  3. Copy prunmgr.exe into a new subdirectory jetty/serviceui and rename it also to SolrService.exe (to provide default service name) - this is the UI that allows to correct some of the parameters of the service after it had been setup via the command line.

  4. Make sure that computer’s environmental variables have JAVA_HOME defined for system variables, not just for user’s (run sysdm.cpl as Administrator). The variable value should look something like _C:\Progra~1\Java\jre7 _. Otherwise, attempting to start the service will produce the following message in the daemon/service logs: Unable to find Java Runtime Environment.

  5. Run the service registration (with renamed prunsrv) as the Administrator on the command prompt after replacing <_SOLRDIR_> with the actual path to the Solr installation as setup above.  The command below should be all on a single line (with spaces instead of line breaks): SolrService.exe //IS//SolrService –DisplayName="Solr Service” –Install=<SOLRDIR>\jetty\SolrService.exe –LogPath=<SOLRDIR>\jetty\logs –LogLevel=Debug –StdOutput=auto –StdError=auto –StartMode=java –StopMode=java –Jvm=auto ++JvmOptions=-Djetty.home=<SOLRDIR>\jetty ++JvmOptions=-DSTOP.PORT=8087 ++JvmOptions=-DSTOP.KEY=stopsolr ++JvmOptions=-Djetty.logs=<SOLRDIR>\jetty\logs ++JvmOptions=-Dorg.eclipse.jetty.util.log.SOURCE=true ++JvmOptions=-XX:MaxPermSize=128M –Classpath=<SOLRDIR>\jetty\start.jar –StartClass=org.eclipse.jetty.start.Main ++StartParams=OPTION=ALL ++StartParams=<SOLRDIR>\jetty\etc\jetty.xml –StopClass=org.eclipse.jetty.start.Main ++StopParams=–stop ++JvmOptions=-Dsolr.solr.home=<SOLRDIR> –StartPath=<SOLRDIR>\jetty

  6. Run the service:

    1. SolrService.exe start
    2. Check the log files in the log subdirectory (usually commons-daemon..log) for messages.
    3. If there is an error message, run serviceui\SolrService.exe and try to correct possible problems. An account that runs the service may need to switch to one with full access to the directories (e.g. Administrator).
    4. Run SolrService.exe stop to stop the service and try starting again. If error log shows problems with stopping and the Services control panel shows the service as ‘starting’, see the troubleshooting section below on how to kill a run-away service.
    5. The success criteria here is being able to access Solr’ Web Admin UI from http://localhost:8983/solr (again).
  7. In the Services control panel, change status of the service Solr Service from manual to automatic to ensure it survives restart. Try stopping and starting the service from the Services control panel to test that it works. Use Solr’ Web Admin UI to verify that it has stopped/started correctly.

Updating Solr configuration

  1. Update would usually involve changes to schema.xml and - much more rarely - to solrconfig.xml .
  2. Most of the time, the core can be reloaded from the Solr’s Web Admin UI to account for the new configuration.
  3. If the changes are significant (e.g. new collection or some deep server settings), the service itself may need to be restarted.

Upgrading Solr

  1. Download and unpack the latest 4.x version of Solr.
  2. Stop Solr service.
  3. Delete and re-copy the directories into jetty subdirectory as per the initial-installation instructions above, with two exceptions:
    1. Keep logs directory, which contains production logs.
    2. Delete solr-webapp directory, which is an expanded version of - now obsolete - webapps/solr.war. If this is not done, you will get version mismatch between old and new content. The solr-webapp directory will be regenerated on the next Jetty restart.
  4. If you need to update schema or config, do it now while the service is down.
  5. Restart the service.
  6. If you are running some persistent client, you may need to restart that as well.
  7. Test from Web Admin UI interface that the service is running.

 Troubleshooting service setup

If a service is misconfigured, Java runtime not found or something else goes wrong, you may get a run-away service that refuses to start and stop properly from the control panel. In which case, you may need to use command line tools (possibly as Administrator) to find and kill the stuck service:

  1. sc queryex
  2. taskkill /PID /F

In here,  is the process ID for the solr service that is stuck.


If you enjoyed this article, you may also like my Solr book: Instant Apache Solr for Indexing Data How-to.

You may also benefit from other information resources available at solr-start.com.