TopShelf installs several identical services on one computer

I am trying to create a windows service using TopShelf. Everything works fine with a single instance of the service. However, when I copy the entire service folder to another location, and then run the installation in place, it just freezes at startup.

I assign the name servicename, description, displayaname based on the value in the configuration files, so no name conflict occurs.

+8
topshelf
source share
2 answers

This is the instancename service you need to distinguish.

From the documentation :

service.exe [verb] [-option: meaning] [-switch]

install installs service

-instance instance name when registering a service multiple times

So you can use:

 service.exe install -instance:FirstInstanceOfMyService service.exe install -instance:SecondInstanceOfMyService 
+22
source share

If you want to set the instance name of the service in the configuration file, you can set the instance name programmatically as follows:

 var instanceName = ConfigurationManager.AppSettings["Instance"]; HostFactory.Run(hostConfigurator => { ... hostConfigurator.SetDisplayName("My service"); hostConfigurator.SetDescription("My service that does something"); hostConfigurator.SetServiceName("MyService"); hostConfigurator.SetInstanceName(instanceName); } 

So, during installation you only run

  MyService.exe install 
+5
source share

All Articles