Here is described other alternativeI was always annoyed by the need to installing SOLRuse external applications to run Solr as a Windows Serviceservice. Pure Some time ago I found a PowerShell script that allows you to write services for Windows in PowerShell. I decided to adopt it to run Solr as a Windows service. I cleaned up the code with all the unnecessary functions.
The full script is available on my gist : https://gist.github.com/RobsonAutomator/6a74c6dfceb6bdcde9c27be9f2d36256
Configuration Configuration is a place where we can specify the port on which Solr will work and the amount of memory used by Java. The SOLR_HOME variable is used to locate the location where Solr is installed. If it is not set, the script will exit displaying the message: Solr.cmd not exist:
#region Solr configuration
$solrPort = '8983'
$solrMemory = '512m' # eg. 1g 4g
$solrHome = [environment]::GetEnvironmentVariable("SOLR_HOME",[EnvironmentVariableTarget]::Machine)
$solrRoot = Split-Path -Path (Split-Path -Path $solrHome -Parent) -Parent
$sorlStartCmd = Join-Path -Path $solrRoot -ChildPath "bin\solr.cmd"
if( -not (Test-Path -Path $sorlStartCmd) )
{
Write-Warning "Solr.cmd not exist: $sorlStartCmd"
return
}
#endregion
Start In the region 'Solr Start' there is a code to run Solr:
#region Solr start
Log "$scriptName Starting $sorlStartCmd with parameteres start -f -p $solrPort -m $solrMemory"
&$sorlStartCmd start -f -p $solrPort -m $solrMemory
#endregion
Stop In the region "Solr Stop" there is a code to stop Solr:
#region Solr stop
&$sorlStartCmd stop -p $solrPort
#endregion
Setup First of all You have to run script with administrator rights Use this script is extremally simple. First run script with parameter -Setup This will create PSSolrService.exe and PSSolrService.ps1 in the folder:
$installDir = "${ENV:ProgramFiles}\$serviceName"
When PSSolrService is installed then use -Start parameter to start service. Till now you can start/stop PSSolrService as each Windows service.
Blog post: http://lets-share.senktas.net/2017/11/solr-as-a-service.html