【问题标题】:Is there a recovery option to start service regardless of dependant service state?无论从属服务状态如何,是否有恢复选项来启动服务?
【发布时间】:2019-04-10 23:57:02
【问题描述】:

关键服务ServiceB、ServiceC和ServiceD必须在非关键ServiceA之后启动(ServiceA监控B、C和D,但对操作并不关键)。

如果启动 ServiceA 有任何问题,我们仍然需要启动 B、C 和 D。否则我们总是希望首先启动 ServiceA。如果 A 崩溃(在运行期间停止),我们不希望停止 B、C 或 D

所有服务都设置为自动启动。 (我们不能对B、C和D使用延迟启动,因为时间不合适,我们不想更改其他延迟服务的默认2分钟)

已在服务 B、C 和 D 上设置了依赖关系,因此如果必要的服务未运行,它们将始终启动必要的服务。如果 ServiceA 停止,这些将停止。

设置依赖的命令如下:

sc config ServiceB depend= ServiceA

我们正在探索系统的恢复选项,该选项将启动 B、C 和 D,无论 A 在多次尝试后是否无法启动。

如果无法通过 SC.exe 或通过配置 Windows 10 进行配置,那么我们可以恢复使用启动脚本或自定义服务控制应用程序,因为我都已经构建了,但更喜欢这种更简洁的配置选项操作系统。

是否可以为服务组配置不同的延迟启动等待值?

任何建议或编辑表示赞赏。 TIA

【问题讨论】:

  • 请注意,我认为这更像是一个 Windows 操作系统问题,但我目前正在开发一个 VBScript 解决方案来实现,如果上述情况不可行,我将发布该解决方案。它还需要以编程方式完成以实现自动化。
  • 怎么知道A有没有被绞死?它可能看起来仍在运行
  • 我不知道,但监视仪表板的人会收到警报并打开票证进行调查。 A 是第三方,但 B、C 和 D 是我们自己的,所以我们不想影响我们自己的系统来适应。下面的 VBScript 答案比预期的处理得更好,但我确实必须提升以允许对第三方服务进行适当的服务控制。
  • 另一种选择是联系 A 的开发人员,看看他们是否可以在运行时连接到我们的服务,而不是需要对它们进行排序,但这可能不可行。

标签: windows


【解决方案1】:

因为我们已经运行了一个启动脚本,所以我很快就把它放在一起。这并不理想而且有点低效,但它确实有效。将 ServiceB、C 和 D 设置为手动启动并使用它来启动它们可能会达到预期的结果,而无需上述依赖项。

Set WshShell = WScript.CreateObject("WScript.Shell")
If WScript.Arguments.Length = 0 Then
  Set ObjShell = CreateObject("Shell.Application")
  ObjShell.ShellExecute "wscript.exe" _
    , """" & WScript.ScriptFullName & """ RunAsAdministrator", , "runas", 1
  WScript.Quit
End If

If Not ServiceAction("ServiceA", -1) = "RUNNING" Then 
    'Stop the services if they are running
    ServiceAction "ServiceB", 0
    ServiceAction "ServiceC", 0
    ServiceAction "ServiceD", 0
    'Start the services in sequence
    ServiceAction "ServiceA", 1
    ServiceAction "ServiceB", 1
    ServiceAction "ServiceC", 1
    ServiceAction "ServiceD", 1
End If

Function ServiceAction(service_name, service_action)
    'Start Service
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & service_name & "'")
    For Each objService in colListOfServices
        If service_action = -1 Then 
            ServiceAction = UCase(objService.State)
        ElseIf service_action = 1 Then 
            ServiceAction = objService.StartService()
        ElseIf service_action = 0 Then
            ServiceAction = objService.StopService()
        End If
    Next
    'For debugging
    WScript.Echo "WMI CODE: "&ServiceAction
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    • 2016-08-04
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 1970-01-01
    相关资源
    最近更新 更多