我们有这个开源应用程序,有三(3)个服务。 为了这个问题的目的,我们称它们为A , B和C.
现在,他们必须按照特定的顺序closures。 那个顺序是A然后B然后C.
如果B在A之前closures,那么我们会遇到各种各样的问题。 如果C在B或A之前closures,情况也是如此。另外,由于有多less用户正在使用它,每个服务可能需要不同的时间closures。
哦,这需要被包装在一个DOSbatch file或非技术用户可以只需双击启动。 (PowerShell不是没有问题,但我从来没有使用它)。 另外,我是一个C#编码器,所以也可以使用。
无论如何,当重新启动时,需要发生以下情况:
1) Initiate shutdown of service A 2) When service A is down, it should trigger the shutdown of service B 3) When service B is down, it should trigger the shutdown of service C 4) When service C is down, it should trigger the START UP of service A 5) When service A is UP, it should trigger the START UP of service B 6) When service B is UP, it should trigger the START UP of service C
所以,正如你所看到的,每个停止/开始需要等待前面的完成,然后继续前进。 而且由于每个服务可能需要几秒钟到几分钟的时间,所以我们不能使用任何种类的计时技巧。
build议非常感谢。
谢谢!
你可以使用PowerShell来做到这一点。 要停止服务,请使用Stop-Service命令。 启动服务是使用启动服务命令。 因此,您可以创build一个脚本,为每个需要停止的服务创build一个如下所示的条目:
Stop-Service ServiceA do { Start-Sleep -Milliseconds 200} until ((get-service ServiceA).status -eq 'Stopped')
并启动服务:
Start-Service ServiceA do { Start-Sleep -Milliseconds 200} until ((get-service ServiceA).status -eq 'Running')
然后,您可以将这些代码块中的6个脚本串在一起,保存为.ps1文件,然后从powershell提示符运行它,如下所示:
PS C:\> C:\Path\To\Script\script.ps1