TopShelf在同一台机器上安装多个相同的服务

Eat*_*oku 12 topshelf

我正在尝试使用TopShelf创建Windows服务.一个服务实例一切正常.但是,当我将整个服务文件夹复制到另一个位置,然后在该位置运行安装时,它只是挂起"启动".

我根据配置文件中的值分配servicename,description,displayaname,因此没有命名冲突.

And*_*rew 25

instancename是您需要区分的服务.

文档:

service.exe [动词] [-option:value] [-switch]

安装安装服务

-instance多次注册服务时的实例名称

所以你可以使用:

service.exe install -instance:FirstInstanceOfMyService

service.exe install -instance:SecondInstanceOfMyService
Run Code Online (Sandbox Code Playgroud)


小智 8

如果你想要的是在配置文件中设置服务实例名称,你可以像这样以编程方式设置实例名称:

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);
}
Run Code Online (Sandbox Code Playgroud)

因此,在安装过程中,您只能运行

  MyService.exe install
Run Code Online (Sandbox Code Playgroud)