Start-Service timesout after 20 seconds

Hi,

I’m starting a windows service using Powershell Start-Service in a deploy step, but that command waits maximum 20 seconds and returns an error.

Then I log in to the box and run the command Start-Service manually and after 5 seconds the service is started.

What can be causing this? Is there a way to increase the 20 seconds timeout?

Using Octopus 3.3.6.

Edit: This only started happening after our Octopus Upgrade.

Thanks,
Miguel

Hi Miguel,

Thanks for reaching out. Could you send us a deployment log so we can see what might be going on?

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

Thanks,
Dalmiro

Hi Dalmiro,

Follows attached. Also attached the code for the Post Deployment script where it is failing.

Thanks,
Miguel

ServerTasks-5021.log.txt (5 KB)

PostDeploy.txt (254 Bytes)

Hi,

Can anyone help?

Thanks,
Miguel

Hi Miguel,

I can see that you are using your own scripts to install the service, and not using the Octopus built-in Windows Service support. This means that the 20sec timeout is being enforced by the raw PS cmdlet, and not by Octopus.

My first thought is that perhaps after running NServiceBus.host.exe, you need to wait a bit longer before attempting to start the service. Can try adding a small stop before starting the service? Something like this:

Write-Output "Installing the service $ComponentName"
.\NServiceBus.Host.exe $Profile /install /serviceName:$ComponentName /displayName:"MyDisplayName $ComponentName"
Write-Output "Going to start the service $ComponentName"

#Wait
Start-sleep -seconds 20

Start-Service $ComponentName

The other thing you could try is adding a do-while loop that retries a few more times to start the service while the service status -eq “stopped”

Let me know if one of those 2 approaches work.

Best regards,
Dalmiro

Hi,

I tried many things:

$ServiceName = “MyService”

start-job -scriptblock {start-service -name $ServiceName}
do
{

$Service = Get-Service $ServiceName
$ServiceName2 = $Service.Name
$ServiceStatus = $Service.Status
Write-Output "Service.Status: $ServiceStatus"
Write-Output "Waiting for the Service $ServiceName2 to start"
Start-Sleep -s 2

}
while($Service.Status -ne “Running”)

and it looks like $Service.Status is always “stopped”.

Also tried:

$ServiceName = “MyService”

$Service = Get-Service $ServiceName
if ($service.Status -ne ‘Running’)
{
$Service.Start()
}
$Service.WaitForStatus(‘Running’, ‘00:01:00’)
if ($service.Status -ne ‘Running’)
{
Write-Warning ‘Something is fishy here…’
}
$Service #last line of the script

And it times out even tough I can see that after 20 seconds the service status is “Started” in the Services console.

Also in the last line of the script where I just print the $Service variable it shows the following, which is award because I can see the service running in the Services console…

Status Name DisplayName
15:05:01 Info


15:05:01 Info
Stopped MyService MyOwnService

Thanks,
Miguel

Hi,

Also tried to sleep after running the command NServiceBus for 20 seconds like you suggested. Didn’t work.

The strange thing is that in powershell if I run this script in the deployment target it works:

$ServiceName = "MyService"

$Service = Get-Service $ServiceName 
if ($service.Status -ne 'Running') 
{ 
    $Service.Start() 
} 
$Service.WaitForStatus('Running', '00:01:00') 
if ($service.Status -ne 'Running') 
{ 
    Write-Warning 'Something is fishy here...' 
} 
$Service #last line of the script

But in Octopus doesn’t work???

Hi,

Found the problem.

Someone from other team added my project to their server. So it was failing in another server.

That’s why I don’t like shared environments!

Thanks,
Miguel

Hi Miguel - Glad you were able to figure it out!

Cheers