Install NServiceBus.Host as a service using WiX

I am creating an installer for our NServiceBus-based solution using WiX, but I am having problems starting the host service after installation.

If I run the host installer from the command line using NServiceBus.Host.exe /install , it will set a penalty and even start successfully when I start the service.

However, when I create a service in WiX using the ServiceInstall element, it does not start the service. I tried to start the service in my installer using the ServiceControl element, and also after installation from the WIndows Services control panel.

The code I'm trying to use on WiX is:

 <Component Id="NServiceBus.Host" Guid="PUT-GUID-HERE" Win64="yes"> <File Id="NServiceBus.Host" KeyPath="yes" Source="$(var.[Project].TargetDir)NServiceBus.Host.exe" Checksum="yes" /> <ServiceInstall Id="NServiceBus.Host.Install" Name="[Product].Host" DisplayName="[Product]" Type="ownProcess" Account="NT Authority\Network Service" Interactive="no" Start="auto" Vital="yes" ErrorControl="normal"> <ServiceDependency Id="MSMQ" /> <ServiceDependency Id="MSDTC" /> </ServiceInstall> <ServiceControl Id="NServiceBus.Host.Control" Name="[Product].Host" Start="install" Stop="both" Remove="uninstall" Wait="yes" /> </Component> 

I used the same code in other projects to install and start services, so I'm sure the problem is with the NServiceBus node. The service here is also installed correctly, but just does not start.

Has anyone been able to install NServiceBus.Host.exe as a service using WiX? Or does anyone know if there are other steps that occur when starting NServiceBus.Host.exe /install , which I must follow in my WiX installer?

I know that I can create a CustomAction on WiX that launches NServiceBus.Host.exe /install , but I would rather avoid this if possible and install the service correctly (WiX). It also avoids the need for deletion of actions and deletion sequence.

Edit: For reference, this is how I create the queues using WiX MsmqExtension :

 <Component Id="NServiceBus.Host.Queue" Guid="PUT-GUID-HERE" Win64="yes"> <msmq:MessageQueue Id="Queue1" Label="[Product] Host" PathName=".\private$\[Product].Host" Transactional="yes" PrivLevel="optional" /> <msmq:MessageQueue Id="Queue2" Label="[Product] Host Retries" PathName=".\private$\[Product].Host.Retries" Transactional="yes" PrivLevel="optional" /> <msmq:MessageQueue Id="Queue3" Label="[Product] Host Timeouts" PathName=".\private$\[Product].Host.Timeouts" Transactional="yes" PrivLevel="optional" /> <msmq:MessageQueue Id="Queue4" Label="[Product] Host Timeouts Dispatcher" PathName=".\private$\[Product].Host.TimeoutsDispatcher" Transactional="yes" PrivLevel="optional" /> </Component> 
+4
source share
2 answers

You are almost there. You need to pass the command line arguments expected by NServiceBus.Host.exe to the Arguments attribute of the ServiceInstall tag, for example

 <ServiceInstall Id="NServiceBus.Host.Install" Name="[Product].Host" DisplayName="[Product]" Type="ownProcess" Account="NT Authority\Network Service" Interactive="no" Start="auto" Vital="yes" ErrorControl="normal" Arguments="-service NServiceBus.Production /serviceName:[Product].Host"> 

Install your service first using the NSB host, then peek all the command line arguments from the Windows service and put them into your WiX installer.

Edit:
If you don't want to trigger custom actions to force NSB to create queues and / or do other things during the WiX @ installation, you can achieve a similar effect by adding a custom NSB profile in your code, for example

 namespace YourNamespace { public class YourProfile : NServiceBus.IProfile { } public class YourProfileBehaviour : IHandleProfile<YourProfile> { public void ProfileActivated() { WindowsInstallerRunner.RunInstallers = true; } } } 

Remember that when using the profile above, the NSB installer code will be run (for example, if necessary, check and add queues) each time the service is restarted. I think there are trade-offs in both directions.

+1
source

You should not try to replicate the NServiceBus host installer on WiX. There are many things that happen and they will change with each release, so anything you try will be very fragile.

Instead of the ServiceInstall element, you just have to run the host with the right command line handlers and let NServiceBus take care of itself. I'm really not familiar with WiX, but I guess there is some way to execute an arbitrary executable using the args command line?

To be clear

Yes, it is possible to set the NServiceBus endpoint as a service with WiX. I say that you SHOULD NOT, not that you cannot.

If you do not use the NServiceBus installer to set the endpoint, you will skip queuing and other tasks that the NServiceBus Host causes that WiX (without its knowledge of how NServiceBus works) cannot.

+1
source

Source: https://habr.com/ru/post/1497727/


All Articles