Cluster: Generic Script – Rouge Process Cleanup/Terminate
I came across an interesting issue whilst clustering a CODA application server on a Windows Server 2003 Enterprise Microsoft Cluster. CODA spawns multiple processes after service startup, these processes are not services and as a result the cluster is not aware of them. When the CODA services are stopped theadditional processes are not always cleaned up. If the services are started again they will fail with a bind error.
I created a Cluster Generic Script to cleanup ‘rogue’ processes on resource group stop and start. Initially the script below contained a process.terminate() function, however this does not work for SYSTEM owned process. I therefore explored using taskkill.exe which is built into Windows, this means that no additional components are required to get this script working.
‘Chris’ CODA Fix Cluster Script – Created 14/01/2011
Dim WshShell, oExec, oLooksAlive, oIsAlive, oWait, objWMIService, colProcess, objProcess, strComputer, objShell
Set WshShell = CreateObject(“WScript.Shell”)processName = “oasasv.exe”
‘On Error Resume Next
Function Online( )
Resource.LogInformation “Entering Online”
On Error Resume Next
If CheckProcess > 0 Then KillProcess
If CheckProcess > 0 Then
Resource.LogInformation “Rougue ‘” & processName & “‘ process still present, FAILED to kill…”
Online = False
Else
Online = True
End If
If Err.Number > 0 Then
Resource.LogInformation Err.Details
Resource.LogInformation oExec.StdErr.ReadAll
End If
End FunctionFunction Offline( )
Resource.LogInformation “Entering Offline”
If CheckProcess > 0 Then KillProcess
If Err.Number > 0 Then
Resource.LogInformation Err.Details
Resource.LogInformation oExec.StdErr.ReadAll
End If
Offline = True
End FunctionFunction LooksAlive( )
Resource.LogInformation “Entering LooksAlive”
LooksAlive = True
End FunctionFunction IsAlive( )
Resource.LogInformation “Entering IsAlive”
IsAlive = True
End FunctionFunction Open( )
Open = 0
End FunctionFunction Close( )
Close = 0
End FunctionFunction Terminate( )
Resource.LogInformation “Entering Terminate”
If Err.Number > 0 Then
Resource.LogInformation Err.Details
Resource.LogInformation oExec.StdErr.ReadAll
End If
Terminate = True
End FunctionFunction CheckProcess ()
CheckProcess = 0
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Set colProcess = objWMIService.ExecQuery (“Select * from Win32_Process where Name = ‘” & processName & “‘”)
On Error Resume Next
For Each objProcess in colProcess
CheckProcess = CheckProcess + 1
Next
End FunctionFunction KillProcess ()
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Set colProcess = objWMIService.ExecQuery (“Select * from Win32_Process where Name = ‘” & processName & “‘”)
On Error Resume Next
For Each objProcess in colProcess
Set objShell = CreateObject(“WScript.Shell”)
objShell.Run “taskkill.exe /F /IM ” & processNameResource.LogInformation “Killed rougue ” & processName & “ process…”
Next
End Function