在服务器上安装同一个windows服务的多个实例 [英] Installing multiple instances of the same windows service on a server

查看:27
本文介绍了在服务器上安装同一个windows服务的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们开发了一个 Windows 服务来向我们的客户端应用程序提供数据,一切都进行得很顺利.客户端提出了一个有趣的配置请求,需要在同一台服务器上运行该服务的两个实例并配置为指向不同的数据库.

So we've produced a windows service to feed data to our client application and everything is going great. The client has come up with a fun configuration request that requires two instances of this service running on the same server and configured to point at separate databases.

到目前为止,我还没有能够做到这一点,希望我的 stackoverflow 成员能够给出一些关于原因的提示.

So far I haven't been able to get this to happen and was hoping my fellow stackoverflow members might be able to give some hints as to why.

当前设置:

我已经设置了包含 Windows 服务的项目,从现在起我们将其称为 AppService,以及处理自定义安装步骤的 ProjectInstaller.cs 文件,以根据应用程序中的键设置服务名称.配置如下:

I've set up the project that contains the windows service, we'll call it AppService from now on, and the ProjectInstaller.cs file that handles custom installation steps to set the service name based on a key in the App.config like so:

this.serviceInstaller1.ServiceName = Util.ServiceName;
this.serviceInstaller1.DisplayName = Util.ServiceName;
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

在这种情况下,Util 只是一个静态类,它从配置文件中加载服务名称.

In this case Util is just a static class tha tloads the service name from the config file.

从这里开始,我尝试了两种不同的方法来安装这两个服务,但都以相同的方式失败.

From here forward I have tried two different ways to get both services installed and both have failed in an identical way.

第一种方法是简单地安装服务的第一个副本,将安装目录复制并重命名,然后在修改应用配置后运行以下命令以更改所需的服务名称:

The first way was to simply install the first copy of the service, copy the installed directory and renamed it, and then ran the following command after modifying the app config to change the desired service name:

InstallUtil.exe /i AppService.exe

当这不起作用时,我尝试创建第二个安装程序项目,编辑配置文件并构建第二个安装程序.当我运行安装程序时,它运行良好,但该服务没有出现在 services.msc 中,所以我针对第二个已安装的代码库运行了前面的命令.

When that didn't work I tried to create a second installer project, edited the config file and built the second installer. When I ran the installer it worked fine but the service did not show up in services.msc so I ran the previous command against the second installed code base.

两次我都从 InstallUtil 收到以下输出(仅相关部分):

Both times i received the following output from InstallUtil (relevant parts only):

运行事务安装.

开始安装的安装阶段.

正在安装服务应用服务二...服务应用服务二已成功安装.在日志应用程序中创建 EventLog 源应用服务二...

Installing service App Service Two... Service App Service Two has been successfully installed. Creating EventLog source App Service Two in log Application...

在安装阶段发生异常.System.NullReferenceException: 未将对象引用设置为对象的实例.

An exception occurred during the Install phase. System.NullReferenceException: Object reference not set to an instance of an object.

安装的回滚阶段开始.

正在将源应用服务二的事件日志恢复到之前的状态.正在从系统中删除服务应用程序服务二...Service App Service 2 已成功从系统中删除.

Restoring event log to previous state for source App Service Two. Service App Service Two is being removed from the system... Service App Service Two was successfully removed from the system.

回滚阶段成功完成.

事务安装已完成.安装失败,已执行回滚.

The transacted install has completed. The installation failed, and the rollback has been performed.

抱歉这篇冗长的帖子,想确保有足够的相关信息.到目前为止让我感到困惑的部分是它指出服务的安装成功完成,并且只有在它创建了 NullReferenceException 似乎被抛出的 EventLog 源之后.因此,如果有人知道我做错了什么或有更好的方法,我们将不胜感激.

Sorry for the long winded post, wanted to make sure there is enough relevant information. The piece that so far has me stumped is that it states that the installation of the service completes successfully and its only after it goes to create the EventLog source that the NullReferenceException seems to get thrown. So if anyone knows what I'm doing wrong or has a better approach it would be much appreciated.

推荐答案

您是否尝试过 sc/service controller util?输入

Have you tried the sc / service controller util? Type

sc create

在命令行,它会给你帮助条目.我想我过去为 Subversion 做过这件事,并使用了 这篇文章作为参考:

at a command line, and it will give you the help entry. I think I've done this in the past for Subversion and used this article as a reference:

http://svn.apache.org/repos/asf/subversion/trunk/notes/windows-service.txt

这篇关于在服务器上安装同一个windows服务的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆