Last active
October 10, 2016 06:23
-
-
Save peaeater/eeb9593dfe30b5ab84c9 to your computer and use it in GitHub Desktop.
Creates a Windows Service for Solr 5.3.1 with nssm.exe. Writes stdout and stderr to log. Put this Powershell script in the Solr bin folder with solr.cmd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| create-jetty-service.ps1 | |
| This script needs to be run once, to create the service. | |
| Service name is mandatory. | |
| Requires nssm.exe (Non-Sucking Service Manager https://nssm.cc). | |
| The script assumes it is located in the Solr 5.x \bin folder with solr.cmd. | |
| N.B. This operation requires elevated permissions. Either run script from Admin version of PS console, or allow to run when it asks. | |
| -- Peter Tyrrell | |
| #> | |
| param( | |
| [Parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0)] | |
| [string]$service, | |
| [Parameter(Mandatory=$false,ValueFromPipeline=$true,Position=1)] | |
| [string]$port = "8983" | |
| ) | |
| # get path of currently executing script | |
| function Get-ScriptDirectory | |
| { | |
| $Invocation = (Get-Variable MyInvocation -Scope 1).Value | |
| Split-Path $Invocation.MyCommand.Path | |
| } | |
| # set variables | |
| $scriptdir = Get-ScriptDirectory | |
| $app = "$scriptdir\solr.cmd" | |
| $solrhome = (resolve-path (join-path $scriptdir ..\cores)).Path | |
| $logdir = (resolve-path (join-path $scriptdir ..\server\logs)).Path | |
| # install service (run in foreground with -f or nssm constantly recycles it) | |
| .\nssm install $service "$app" AppDirectory "$scriptdir" | |
| .\nssm set $service AppParameters start -f -V -p $port -s "$solrhome" | |
| .\nssm set $service Description "Runs Solr at http://localhost:$port/solr. Find logs at $logdir." | |
| .\nssm set $service Start SERVICE_AUTO_START | |
| # Log console output, overwrite on service restart | |
| .\nssm set $service AppStdout "$logdir\service.log" | |
| .\nssm set $service AppStderr "$logdir\service.log" | |
| .\nssm set $service AppStdoutCreationDisposition 2 | |
| .\nssm set $service AppStderrCreationDisposition 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment