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.
- 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).
- Download latest Solr (here Solr 4.3.1) and unpack it somewhere.
- Create a directory where your Solr configuration and Jetty will live (e.g. C:\Services\SolrService, which we will refer to as <_SOLRDIR_>).
- 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.
- Under the <_SOLRDIR_>, create subdirectory called jetty.
- Copy the following directories and the files into the jetty subdirectory from the Solr’s example directory:
- resources (Solr 4.3+)
- From the command line in the jetty directory, run the Solr server to make sure it works:
- java -Dsolr.solr.home=.. -jar start.jar
- Ensure that Solr is accessible at: http://localhost:8983/solr/
- Stop the server (Ctrl-C)
Service setup for availability
- Download Apache Commons’ Daemon package for Windows (make sure to get the Windows package that includes .exe files).
- Copy platform-appropriate prunsrv.exe into the jetty directory and rename it to SolrService.exe – this is the actual Windows service executable.
- 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.
- 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.
- 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
- Run the service:
- SolrService.exe start
- Check the log files in the log subdirectory (usually commons-daemon.<date>.log) for messages.
- 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).
- 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.
- The success criteria here is being able to access Solr’ Web Admin UI from http://localhost:8983/solr (again).
- 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
- Update would usually involve changes to schema.xml and – much more rarely – to solrconfig.xml .
- Most of the time, the core can be reloaded from the Solr’s Web Admin UI to account for the new configuration.
- If the changes are significant (e.g. new collection or some deep server settings), the service itself may need to be restarted.
- Download and unpack the latest 4.x version of Solr.
- Stop Solr service.
- Delete and re-copy the directories into jetty subdirectory as per the initial-installation instructions above, with two exceptions:
- Keep logs directory, which contains production logs.
- 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.
- If you need to update schema or config, do it now while the service is down.
- Restart the service.
- If you are running some persistent client, you may need to restart that as well.
- 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:
- sc queryex
- taskkill /PID <PID> /F
In here, <PID> 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.