Skip to content

Instantly share code, notes, and snippets.

@nskerl
Last active August 29, 2015 13:56
Show Gist options
  • Save nskerl/8985365 to your computer and use it in GitHub Desktop.
Save nskerl/8985365 to your computer and use it in GitHub Desktop.
# the service params (Octo can/should pass these in)
$serviceName = "MyCompany.MyService"
$serviceExe = "MyService.exe"
$fullPath = Join-Path -Path $OctopusPackageDirectoryPath -ChildPath $serviceExe
# resolve service context
$service = Get-Service MyCompany.MyService -ErrorAction SilentlyContinue
if (! $service)
{
Write-Host "Installing as a new service..."
& $fullPath "install" | Write-Host
}
else
{
Write-Host "Stopping service..."
Stop-Service $service.Name -Force
Write-Host "Reconfiguring service..."
& "sc.exe" config $service.Name binPath= $fullPath start= demand | Write-Host
Write-Host "Restarting service..."
Start-Service $service.Name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment