0

我想在故障转移时使用 Windows 故障转移集群中的通用脚本在故障转移时重新启动 PrTomcat 服务,但 tomcat 需要一些时间才能停止(有时 5 秒到 150 秒),下面的代码无法重新启动服务,知道吗?根据集群记录只有一个来自脚本的条目并且没有错误01-11-2021 23:18:07 StopService PrTomcat Stop Pending

Function Online( )

On Error Resume Next
'
'   For the local strComputer only...
'
strComputer = "."
strServiceName = "PrTomcat"

StopService strComputer, strServiceName

StartService strComputer, strServiceName
Online =  true
End Function
 
Function LooksAlive( )
LooksAlive = true
End Function
 
Function IsAlive( )
IsAlive = true
End Function



Sub StopService(strComputer, strServiceName)
  Dim cimv2, oService, Result

  'Get the WMI administration object    
  Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\cimv2")

  'Get the service object
  Set oService = cimv2.Get("Win32_Service.Name='" & strServiceName & "'")
  
  'Check base properties
  If Not oService.Started Then
    ' the service is Not started
    Resource.LogInformation "The service " & strServiceName & " is Not started"
    exit Sub
  End If

  If Not oService.AcceptStop Then
    ' the service does Not accept stop command
    Resource.LogInformation "The service " & strServiceName & " does Not accept stop command"
    exit Sub
  End If

  'Stop the service
  Result  = oService.StopService
  If 0 <> Result Then
    Resource.LogInformation "Stop " & strServiceName & " error: " & Result
    exit Sub 
  End If 
  
  Do While oService.Started
    'get the current service state
    Set oService = cimv2.Get("Win32_Service.Name='" & strServiceName & "'")

    Resource.LogInformation now & " StopService PrTomcat " & oService.State
    Wscript.Sleep 15000
  Loop
End Sub


Sub StartService(strComputer, strServiceName)
  Dim cimv2, oService, Result

  'Get the WMI administration object    
  Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\cimv2")

  'Get the service object
  Set oService = cimv2.Get("Win32_Service.Name='" & strServiceName & "'")

  
  
  Set oService = cimv2.Get("Win32_Service.Name='" & strServiceName & "'")
  Do While StrComp(oService.State,"Stop Pending",1) = 0
    Wscript.Sleep 15000
    Resource.LogInformation "The service " & strServiceName & " Stop Pending."
  Loop
  
  'Start the service
  Result = oService.StartService
  If 0 <> Result Then
    Resource.LogInformation "Start " & strServiceName & " error:" & Result
    exit Sub 
  End If 
  
  Do While InStr(1,oService.State,"running",1) = 0 
    'get the current service state
    Set oService = cimv2.Get("Win32_Service.Name='" & strServiceName & "'")
    
    Resource.LogInformation now & " StartService PrTomcat " & oService.State
    Wscript.Sleep 200
  Loop   
End Sub
4

0 回答 0