自动更新Windows服务 [英] Auto-update a Windows Service

查看:214
本文介绍了自动更新Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将要开发一个程序,该程序将在多个客户端的后端服务器(具有Internet访问权限)上作为Windows服务安装并运行.我没有物理访问服务器.我正在研究的是一种可靠地对程序进行更新的方案.

I am about to develop a program which will be installed and run as a Windows Service on the back-end servers (with internet access) of several clients. I do not have physical access to the servers. What I am working on is a scheme for reliably rolling out updates to the program.

我已经花了很多时间来寻找Windows Service自动更新的最佳实践,但是却找不到有用的信息.大多数技术(例如ClickOnce)似乎主要是针对基于Windows窗体的应用程序.

I have spend quite a lot of time looking for best practices for Windows Service auto-updates, but have found very little useful information. Most techniques, such as ClickOnce, seem to cater primarily for Windows Forms-based applications.

我当前的计划是:

  • 有可用更新时,请下载正在运行的服务,安装并启动更新服务.
  • 更新服务将下载主服务的新版本,并将其与当前仍处于活动状态的版本并排安装.
  • 更新服务接下来将停止旧版本,然后启动该服务的新版本.
  • 新版本在启动期间会禁用更新服务.

对我来说,一些重要的问题是:

Some important concerns for me are:

  • 能够处理主要服务和更新服务的更新
  • 在更新过程中的任何时候都能够处理诸如电源故障或连接故障之类的中断

我想知道的是,这是否是解决此问题的常用方法,并且/或者我是否缺少任何关键的信息.是太复杂了,还是太简单了?您将如何做(或者更好的是,您如何成功地做到了这一点)?

What am wondering is if this a common way to solve this problem and/or if I am missing anything crucial. Is it too complicated, or perhaps far too simplistic? How would you have done it (or, even better, how have you done this successfully)?

谢谢!

推荐答案

去年我遇到了同样的问题,我也遇到了很多同样的问题.几点建议:

I was faced with the same problem last year and I wrestled with a lot of the same questions. A few bits of advice:

  • 由于任何一项服务都可能被更新, 两种服务都将作为 其他的更新者.服务A将 更新服务B,反之亦然.为了 因此,我建议您简单地运行 两种服务都在任何时候.除非 您担心真正加载 使用以下命令关闭服务器 确实存在更新呼叫, 启用/禁用服务管理 不值得的开销.

  • Since either service may be updated, both services will function as updaters of the other. Service A will update Service B and vice versa. For this reason, I suggest simply running both services at all times. Unless you are worried about really loading down your server with does-update-exist calls, the enable/disable service management isn't worth the overhead.

无法将类似服务安装在 单机.换句话说,你 无法安装新旧版本的 如果有的话,并排服务 相同的名字.除非你要 使您的更新过程复杂化,我 建议您卸载旧版本 然后安装新版本. 例如,服务A将下载 服务B安装程序,卸载 服务B,安装新版本 服务B,然后运行.服务B 会对服务A执行相同的操作.

Like services can't be installed on a single machine. In other words, you can't install new and old versions of the service side-by-side if they have the same name. Unless you want to complicate your update process, I suggest you uninstall the old version and then install the new version. For example, Service A would download Service B Installer, uninstall Service B, install new version of Service B and then run. Service B would do the same for Service A.

由于每个服务都在管理 其他,他们不仅应该检查 可用的更新,但他们应该 验证彼此的健康状况.为了 例如,服务A会检查 服务B是否存在以及是否存在 跑步.如果健康检查失败, 解决问题的步骤列表 并让服务运行 由服务A完成. 健康检查和恢复操作 不管什么问题,现在将覆盖您 随着更新而产生,初始 安装或常规操作.

Since each service is managing the other, they should not only check for available updates but they should verify each other's health. For example, Service A would check to see if Service B exists and if it is running. If the health check fails, a list of steps to resolve the issue and get the service running would be completed by Service A. Executing the health check and recovery operations will cover you now matter what issue arises with the update, initial install or general operations.

在两个客户端上都进行足够的登录 和服务器.您将要跟踪 采取了什么行动以及何时采取行动. 例如,服务A可能会在 正在检查更新 执行健康检查并 相关动作.在服务上 (假设您正在调用网络 寻找更新的服务)跟踪 每个服务发出的呼叫.如果 您的服务没有更新 至少你会有 面包屑(或缺少面包屑) 指出问题所在.

Do ample logging on both the client and the server. You'll want to track what actions were taken and when. For example, Service A might when it is checking for updates, when it is executing the health check and associated actions. On the service (assuming you are calling into a web service looking for updates) track the calls made by each Service. If your Services aren't getting updated at least you'll have a trail of breadcrumbs (or lack of breadcrumbs) pointing you to the problem.

从字面上看,有很多潜在的问题与此类解决方案有关:服务未在启动时运行,UAC妨碍了用户,无法由同一用户安装和卸载服务,从而确保用户安装服务的能力充裕权限,连接丢失,在客户端计算机上安装.NET Framework,在必要后进行安装后的重新引导等.

There are literally bunches of potential gotchas with a solution of this sort: services not running at startup, UAC getting in the way, not being able to install and uninstall the services with the same user, ensuring user installing the service has ample permissions, connectivity loss, getting the .NET Framework installed on the client machine, handling reboot after install if necessary, etc.

祝你好运.这是一个很有趣的问题,但没有挫败感就无法解决-尤其是因为正如您所说,没有很多可用的书面信息.

Best of luck. It's a fun problem to solve, but it doesn't go without it's frustration -- especially since, as you said, there isn't a lot of documented information available.

这篇关于自动更新Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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