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

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

问题描述

我有一种情况,一台服务器上的Windows服务不应该启动,直到另一台服务器上的Windows服务启动。我想做的是设置服务依赖关系,但标准的sc< service1> depend = service2似乎并不适应这一点。 >

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

解决方案

同一台机器上的Windows服务之间的依赖关系由服务控制管理器(SCM)进行管理。如果您的服务依赖于不同机器上的服务,SCM将无法/不会帮助您。



因此,您必须获取自己运行的代码,以便以某种方式监控远程服务是否正在运行,并使该代码运行我们必须允许您的服务开始有或没有依赖关系。



在不知道您的服务目的的情况下,很难规定详细的解决方案,但原则上您可能需要您的服务有两种操作模式:一种除了以某种方式监视是否运行它所依赖的远程服务,它不起作用;另一个它执行其全部功能以及继续监视依赖关系



最后一点是至关重要的 - 您将在任何情况必须不断地监视依赖关系,而不仅仅是在服务开始的时候,因为与单机情况不同,远程机器上的SCM不会阻止远程服务被停止,因为它对它的依赖一无所知。


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.

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.

解决方案

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.

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天全站免登陆