Windows Service Configuration

The Windows Service configuration in Octopus 2.x is very problematic as it doesn’t wait for the service to stop before trying to copy files. Which means you continually get files in use error. It took many hours of trial an error to get a working solution. However, i believe the feature should handle this complexity. Here is the powershell i came up with. Please make the Window Service Configuration feature wait for the service to stop and also wait for the process to end!

@@@
$ServiceName = $OctopusParameters[“Octopus.Action.WindowsService.ServiceName”]
$ProcessName = $OctopusParameters[“Octopus.Action.WindowsService.ExecutablePath”]

Write-Host “Finding service ‘$ServiceName’.”

$service = Get-Service $ServiceName -ErrorAction SilentlyContinue

if ($service)
{
Write-Host "The service ‘$ServiceName’ will be stopped."
Write-Host $service

Stop-Service $service.Name -Force

$service.WaitForStatus('Stopped','00:00:45')

# wait to prevent files in use error
Write-Host "Wait for process '$ProcessName' to end."
Wait-Process -Name $ProcessName -Timeout 30 -ErrorAction SilentlyContinue

}
else
{
Write-Host “The service ‘$ServiceName’ was not found.”
}
@@@

Thanks for letting us know. We have this down to fix in the next release: https://github.com/OctopusDeploy/Issues/issues/601

Cheers,
Nick