Skip to content

How to create a Windows Service without using NServiceBus.Host.exe

31/07/2015

NServiceBus is a great tool. Probably the best implementation of a Service Bus (at least in the .Net world).

It even provides us with a program that let’s a run an Endpoint from Visual Studio (during development) as a console application and the same program helps us creating a Windows Service to install the endpoint in production. Unfortunately, the user that run the command (when trying to install the endpoint in production) has to have access to the database.

In my case, I’m developing a software for a company that has a pretty good Continuous Integration/Delivery process. We use Bamboo and that process runs under it owns service account specific for the Build and Deployment processes. That user does not have access to the database (and we don’t want to give it access).

As we can see in the “official Google Group” this is a known and old “thing” (I don’t want to call it issue) click here (BTW, Andreas is the Lead Developer for NServiceBus) and the recomendation is to use SC.exe, so I did and here I want to share how I did it.

To create the service

sc create SERVICE_NAME 
binpath="D:\Temp\Release\NServiceBus.Host.exe -service /serviceName:SERVICE_NAME ASSEMBLY_NAME
obj= ".\SERVICE_ACCOUNT_THAT_IS_GOING_TO_RUN_THE_SERVICE" 
password= "P@ssw0rd1!"  
start=auto

To change the description

sc description SEWRVICE_NAME "Description of the service that will be shown in the service console"

To start the service

sc start SERVICE_NAME

The NServiceBus Documentation, recommends to stop and uninstall a service before doing an update, so this are the instruction I used for it

To stop the service

sc stop SERVICE_NAME

To delete the service

sc delete SERVICE_NAME

I leave here a few link with more documentation about SC.exe

https://technet.microsoft.com/en-us/library/cc754599.aspx


Como crear un Windows Service sin usar NserviceBus.Host.exe

NServiceBus es una herramienta fantástica. Creo que es la mejor implementación de un Service Bus (por lo menos en el mundo de .Net).

NServiceBus incluye un programa que nos permite ejecutar un Endpoint desde Visual Studio (durante el desarrollo) como si fuese una applicación de consola y el mismo programa sirve para crear el servicio en producción. Lamentablemente, el usuario que ejecutar el comando (durante la instalación del endpoint a producción) tiene que tener acceso a la base de datos.

En mi caso, estoy desarrollando una applicación para una compañia que tiene establecido un processo de integración e instalación continuo bastante maduro. Usamos Bamboo y el proceso es ejecutado bajo la identidad de un usuario de servicios que no tiene acceso a la base de datos y no queremos que tenga.

Como se puede ver en el grupo “oficial” de Google para NServiceBus, esta “situación” (no quiero llamarlo probema) es conocida click here (Andreas es Lead Developer en NServiceBus) y su recomendación es usar SC.exe, y eso es lo que hice y quiero mostrar aca.

Crear el servicio

sc create NOMBRE_DEL_SERVICIO 
binpath="D:\Temp\Release\NServiceBus.Host.exe -service /serviceName:NOMBRE_DEL_SERVICIO NOMBRE_DEL_ASSEMBLYL
obj= ".\SERVICE_ACCOUNT_QUE_EJECUTA_EL_SERVICIO" 
password= "P@ssw0rd1!"  
start=auto

Cambiar la descripción

sc description NOMBRE_DEL_SERVICIO "Descripción del servicio que aparece en la consola de servicios"

Ejecutar el servicio

sc start NOMBRE_DEL_SERVICIO

La documentación de NServiceBus recomienda parar y desinstalar el servicio antes de actualizarlo.

Parar el servicio

sc stop NOMBRE_DEL_SERVICIO

Desinstalar el servicio

sc delete NOMBRE_DEL_SERVICIO

Dejo aqui algunos links a la documentación de SC.exe

https://technet.microsoft.com/en-us/library/cc754599.aspx

Advertisements

From → IT

One Comment
  1. Think you saved my bacon today. Thanks for posting this. It’s super useful for configuring Octopus Deploy.

    Cheers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: