I have a windows service that I am deploying using octopus. The deployment is working fine for 90 % of the time. If I deploy the service early in the morning I will get the "The service did not respond to the start or control request in a timely fashion." error. If I run the same deployment again from Octopus it works.
I tried the following suggestion found on the web already.
Ensure the service is stopped changing the powershell script for Octopus. This will wait until the service is stopped before reconfiguring it. We suspected that the service did not shut down correctly.
#ensure that the service was stopped.
Stop-Service $ServiceName
do {
Write-Host "Service not stopped yet...pausing execution for 200 ms"
Start-Sleep -Milliseconds 200
} until ((Get-Service $ServiceName).status -eq 'Stopped')
& "sc.exe" config $service.Name binPath= $fullPath start= auto |
Increase the timeout in the onstart method for the service
protected override void OnStart(string[] args)
{
_eventLog.WriteEntry(_source, "Starting service...", EventLogEntryType.Information);
//adding this to ensure there is enough time to start the service.
this.RequestAdditionalTime(60000);
new TaskFactory().StartNew(() => Start(_cancellationToken.Token), TaskCreationOptions.LongRunning);
IsComplete = true;
}
Like I mentioned, if you deploy the service after the error, then it works. The error only occurs after the service has been running for quite some time eg at least 2 hours. If I deploy back to back every 10 minutes the error does not present it self.
Please help
Ok, so I managed to track down my issue. Our service is dependent on the WinHTTP Web Proxy Auto-Discovery Service , this service gets stopped for some reason after a certain amount of idling time. So when we deploy our service this service is not running and then an exception should be thrown. We did not see the exception because it was swallowed by a try catch.
I added this service as a dependency for our service and now it is working every time. Hope this helps someone in the future.