Installing NServiceBus endpoint as service fails

When using octopus 1.6 we had written scripts for uninstalling/installing our NServiceBus endpoints. We have a lot of configuration that could be removed by using the Service deployment for Octopus 2. Unfortunately, our endpoint services look to install but they won’t start. Using sc.exe on the server to manually install doesn’t work. I get no output and no feedback other than the service wasn’t started.

I am assuming it’s something to do with TopShelf and the fact that that handles installation but wanted to confirm.

Hi,

Depending on how you use TopShelf, I think you need to specify something like this:

-servicename "MyService"

In the “Arguments” setting on the service installer step.

Hope that helps,

Paul

Hi,

I have exactly the same problem. If I install the service using the standard NServiceBus.Host.exe /install the service works fine. However if I use Octopus it doesn’t.

I’m going to use some PS for now but I’d really like to know if there’s a workaround.

Cheers,
Marcus

Hi,

When you use the Octopus windows service feature, you probably have it pointing to NServiceBus.Host.exe with no arguments. But if you run NServiceBus.Host.exe /install and look at the actual service installed in Services.msc, you’ll probably find something different - chances are it passes the path to the current DLL as an argument. You’d need to use the same arguments with the Octopus windows service configuration feature for it to work the same way.

Paul

Just wondering if there’s any result from this? I’m also getting a failure when using OD to do the service install, but it works fine if I run the NSB installation command line. The error I’m getting from the install is:

@@@
The Bus.Email service does not exist; it will be created
Info 16:34:13
sc.exe create “Bus.Email” binPath= ““C:\Octopus\Applications\Live\Bus.EndPoint.Email\4.0.325_3\NServiceBus.Host.exe” /install” DisplayName= “Bus.Email” start= "auto"
Info 16:34:13
[SC] CreateService SUCCESS
Info 16:34:13
Starting the Bus.Email service
Error 16:34:44
Start-Service : Service ‘Bus.Email (Bus.Email)’ cannot be started due to the
Error 16:34:44
following error: Cannot start service Bus.Email on computer ‘.’.
Error 16:34:44
At C:\Program Files\Octopus Deploy\Tentacle\Scripts\Octopus.Features.WindowsSer
Error 16:34:44
vice_BeforePostDeploy.ps1:123 char:2
Error 16:34:44

  • Start-Service $ServiceName
    

Error 16:34:44

  • ~~~~~~~~~~~~~~~~~~~~~~~~~~
    

Error 16:34:44
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceControl
Error 16:34:44
ler:ServiceController) [Start-Service], ServiceCommandException
Error 16:34:44
+ FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Comman
Error 16:34:44
ds.StartServiceCommand
Fatal 16:34:44
PowerShell script returned a non-zero exit code: 1
@@@

In case this is useful to anyone, it does work fine when using a custom PS script in the stage itself. This is what I’m using:

@@@
$exe = $OctopusParameters[‘Octopus.Action.Package.CustomInstallationDirectory’] + ‘\NServiceBus.Host.exe’
$serviceName = $OctopusParameters[‘Bus.ServiceName’]

& $exe /install /servicename:"$serviceName" NServiceBus.Production
Start-Service $serviceName

@@@

Hi Sean!

When you use the Octopus Windows Service feature, Octopus uses sc.exe to create the service, and points the service at the exe you specify. In your output from Octopus you can see this:

sc.exe create “Bus.Email” binPath= “"C:\Octopus\Applications\Live\Bus.EndPoint.Email\4.0.325_3\NServiceBus.Host.exe" /install” DisplayName= “Bus.Email” start= “auto”

So this is saying “Create a Windows Service called Bus.Email. When it starts, it should run NServiceBus.Host.exe /install”. But of course, that is nonsense - NServiceBus.Host.exe /install is for installing a service, not running a service. The command should probably look more like NServiceBus.Host.exe

If you do this:

& $exe /install /servicename:"$serviceName" NServiceBus.Production

Then look at the service configured in the services manager - you’ll find that it actually calls NServiceBus.Host.exe with completely different arguments. Those are the settings you want to use when you create your Windows service the Octopus way.

But given NServiceBus.Host can configure the service for you, it’s probably best to just rely on that and don’t use the built-in Octopus Windows Service configuration feature.

Hope that helps to explain what is going on,

Paul

Hi Paul

Thanks for the explanation. I’m now using custom PS scripts in the step itself with a couple of variables thrown in. As with most things in the Octopus world, it really easy to do!

BTW - I’m recently coming from 1.6 to 2.4 and am really loving the new features and UI. Thanks, this is just brilliant!! :slight_smile:

Cheers

Sean

For what it’s worth, looks like all you need to do is add -servicename "{your serviceName} to the parameters and it should get it working.