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”
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…