Intermittent issue deploying Windows Service

I recently upgraded from Octopus Deploy 2.X to 3.2.19. When trying to deploy a Windows Service using the upgraded server, I am having an intermittent issue getting the service to deploy successfully. The error being caught by Octopus is the following…

Start-Service : Service 'MyWindowsService (MyWindowsService)' cannot be started due to the following error: Cannot start service MyWindowsService on 
computer '.'.

At D:\MyWindowsServicePath\Octopus.Features.WindowsService_BeforePostDeploy.ps1:156 char:15
+     Start-Service <<<<  $ServiceName
+ CategoryInfo          : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand

The System Windows Log has two errors that are thrown at the same time…

A timeout was reached (30000 milliseconds) while waiting for the MyWindowsService service to connect.

And

The MyWindowsService service failed to start due to the following error: 
The service did not respond to the start or control request in a timely fashion.

I did see a suggestion to modify my service’s code; however, when I log into the machine and use the Windows Services console, the service starts up and is running in only a few seconds. This suggest to me that my code isn’t the issue.

I also tried setting the ServicesPipeTimeout registery key to 60000, also called out in that stackoverflow post; however the issue and the errors citing 30000 milliseconds still persist, even after several reboots.

As I mentioned, the issue is intermittent. In a deployment to 16 servers, a few of them will throw the errors. Using Guided Failures, I am able to retry and sometimes successfully deploy the service. If I re-run the whole deployment, a different set of servers will fail. The Retry ad nauseam approach eventually does succeed.

Would you please help me get my service consistently deployed?

Hi,

Thanks for reaching out. I believe we’ve seen a similar to this one before where a small wait between the Service deployment and the attempt to started helped.

Could you try to add a 10sec wait between the deployment and the service start? The code below should work for this

start-sleep -seconds 10

Let me know how it goes

Regards,
Dalmiro

Thank you for your quick response, Dalmiro. I’m not of where to put this command.

I am using the built-in configure feature for a Windows Service, which “creates or reconfigures a Windows Service using sc.exe.” I can setup a Custom deployment scripts feature. Should I add it as a Deployment script or a Post-deployment script?

Hi,

Could you please send us a log of a failed deployment? I’d like to take a look at it first to make sure it matches the scenario we’ve seen before

http://docs.octopusdeploy.com/display/OD/Get+the+raw+output+from+a+task

Regards,
Dalmiro