Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TopShelf install multiple of the same service on the same machine

Tags:

topshelf

I am trying to create windows service using TopShelf. Everything works fine with one instance of the service. However, when I copy the whole service folder to a different location and then run the installation at the location it just hangs on "startup".

I assign the servicename, description, displayaname based on the value in a config files so there is no naming conflict.

like image 416
Eatdoku Avatar asked Aug 02 '12 00:08

Eatdoku


2 Answers

It's the service's instancename that you need to differentiate.

From the documentation:

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

install Installs the service

-instance An instance name if registering the service multiple times

So you could use:

service.exe install -instance:FirstInstanceOfMyService

service.exe install -instance:SecondInstanceOfMyService
like image 89
Andrew Avatar answered Nov 12 '22 12:11

Andrew


If what you want is to set the service instance name in the config file, you can set the instance name programatically like this:

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 the installation you only run

  MyService.exe install
like image 9
D33 Avatar answered Nov 12 '22 12:11

D33