TopShelf install multiple of the same service on the same machine
Asked Answered
T

2

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.

Tabina answered 2/8, 2012 at 0:15 Comment(2)
Come join the mailing list with this, and include the log output if you can. 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.Dogie
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.Tribune
G
31

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
Grin answered 16/10, 2012 at 8:37 Comment(0)
W
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
Were answered 14/1, 2016 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.