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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With