15

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.

Eatdoku
  • 6,569
  • 13
  • 63
  • 98
  • Come join the mailing list with this, and include the log output if you can. https://groups.google.com/forum/#!forum/topshelf-discuss. This will be hard to figure out across SO; however, you can set "instance" name that should allow you to run two of the same services. – Travis Aug 02 '12 at 13:54
  • Are you sure that servicename AND displayname are unique? Tried installing two services with unique servicenames but using same displayname and it didn't worked too. – Bomberlt Sep 04 '14 at 07:03

2 Answers2

30

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
Andrew
  • 12,991
  • 15
  • 55
  • 85
9

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
D33
  • 291
  • 5
  • 11