generic script fails to restart tomcat

103 Views Asked by At

I want to restart PrTomcat service in Primary node on failover using generic script in windows failover cluster with below code but tomcat is taking some time to stop (5 seconds to 150 seconds sometimes) and below code is failing to restart the service, any idea? As per cluster logs only one entry coming from script and no error 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
0

There are 0 best solutions below