如何在同一域中的不同服务器上设置 Windows 服务之间的依赖关系 [英] How to set up dependencies between windows-services on different servers in same domain

查看:22
本文介绍了如何在同一域中的不同服务器上设置 Windows 服务之间的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,在另一台服务器上的 Windows 服务启动之前,不应启动一台服务器上的 Windows 服务.我想做的是设置服务依赖项,但标准 "sc <service1>depend= service2" 似乎不适合这个.

I have a situation where a windows service on one server should not be started until a windows service on a different server has started. What I'd like to do is set the service dependencies but the standard "sc <service1> depend= service2" doesn't seem to cater for this.

我可以将服务代码包装在 TryUntilSuccesful() 类型的调用中,但我想知道是否有推荐的方法来为同一域中的服务器之间的 Windows 服务设置依赖关系.

I could wrap the service code in a TryUntilSuccesful() sort of call but I would like to know if there is a recomended way to set up dependencies for windows services across servers in the same domain.

推荐答案

同一台机器上的 Windows 服务之间的依赖关系由服务控制管理器 (SCM) 管理.如果您的服务依赖于不同机器上的服务,则 SCM 不能/不会帮助您.

Dependencies between Windows Services on the same machine are managed by the Service Control Manager (SCM). The SCM can't/won't help you if your service is dependent on a Service on a different machine.

因此,您必须运行自己的一些代码,以便以某种方式监控远程服务是否正在运行,并且要运行该代码,您必须允许您的服务启动或不启动依赖关系.

Therefore you will have to get some code of your own running in order to monitor in some fashion whether the remote service is running or not, and to get that code running you'll have to allow your service to start with or without the dependency.

在不知道服务目的的情况下很难制定详细的解决方案,但原则上您可能需要您的服务具有两种操作模式:一种是它什么都不做,只是以某种方式监视它所在的远程服务是否依赖正在运行;另一个是它执行其全部功能以及继续监视依赖项.

It's difficult to prescribe a detailed solution without knowing the purpose of your service, but in principle you probably need your service to have two modes of operation: one where it does nothing except monitor in some fashion whether the remote service on which it depends is running; and the another where it performs its full functionality as well as continuing to monitor the dependency.

最后一点至关重要 - 在任何情况下,您都必须持续监控依赖关系,而不仅仅是在服务启动时,因为与单机情况不同,远程计算机上的 SCM 不会阻止远程服务被停止,因为它对你对它的依赖一无所知.

This last point is crucial - you will in any case have to monitor the dependency continuously, not just around the time your service is starting, because unlike the single machine situation, the SCM on the remote machine will not prevent the remote service being stopped, as it knows nothing about your dependency on it.

这篇关于如何在同一域中的不同服务器上设置 Windows 服务之间的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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