Quantcast
Channel: High Availability (Clustering) forum
Viewing all articles
Browse latest Browse all 5654

I have added a generic script to a resource which always fails in windows failover clustering. WScript.Sleep causes it to fail

$
0
0
'************************Variable declaration********************************
Dim servername,objWMIService,wql,results,service,blnServicestopped,blnServiceStarted
dim myNode,ClusterName,otherNode
Dim oShell, appCmd
'************************Variable declaration********************************

'************************Getting Cluster Name and storng  in ClusterName variable***********************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\mscluster")

Set colItems = objWMIService.ExecQuery("Select * from MSCluster_Cluster")
For Each objItem in colItems
ClusterName = objItem.Name
Next
Set objWMIService = Nothing
'************************Getting Cluster Name and storng  in ClusterName variable***********************

'************************Getting Computer Name of system and storng  in myNode variable***********************
Set objWMIService = CreateObject("Wscript.Network") 
myNode = objWMIService.ComputerName 
Set objWMIService = Nothing
'************************Getting Computer Name of system and storng  in myNode variable***********************

'*********************************Getting Computer Name of another node of cluster****************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\mscluster")

Set colItems = objWMIService.ExecQuery("Select * from MSCluster_Node")

For Each objItem in colItems    
    If objItem.Name <> myNode Then 'if computer name is not same as myNode then it is other node assuming that only 2 nodes will be in cluster
otherNode = objItem.Name
    End If 
    
Next
'*********************************Getting Computer Name of another node of cluster****************************


'*********************************Offline Function****************************
'Description: 
'takes all the application services (prep,pass,insert,ais) offline by calling ApplicationFailoverFailback on the system where the applcation services are running (it can be same server or the other server)
'takes all the database services (listener,confdb,masterdb) offline from the system where this script will be triggered by cluster
Function Offline()



Set oShell  = CreateObject("WScript.Shell")
appCmd      = "cluster resource ApplicationFailoverFailback /offline"
oShell.Run appCmd, 4, false
set oShell = NOTHING

servername = "localhost"
set objWMIService = getobject("winmgmts://" & servername)

ServiceName = "OracleServicemasterdb"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results
  if service.state = "Running" then
     service.stopService
   end if
next


blnServicestopped = "false"
Do While blnServicestopped = "false"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results
  if service.state = "Stopped" then
     blnServicestopped = "true"    
  end if
next
loop

ServiceName = "OracleServiceCONFDB"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results
  if service.state = "Running" then
     service.stopService
   end if
next



blnServicestopped = "false"

Do While blnServicestopped = "false"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results
  if service.state = "Stopped" then
      blnServicestopped = "true"    
  end if
next
loop


ServiceName = "OracleOraDb11g_home1TNSListener"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results
  if service.state = "Running" then
     service.stopService
   end if
next

strComputer = "."
Set objWMIService = GetObject( _
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery( _
    "Select * from Win32_Environment ")
Found = False
For Each objItem in colItems
if Found=False then
   If objItem.Name = "ORACLE_HOME" Then
    OraclePath=objItem.VariableValue
'wscript.echo OraclePath
Found=True
   end if
End If
Next

Found = False
For Each objItem in colItems
if Found=False then
   If objItem.Name = "ORACLE_HOME_32" Then
    OraclePath32=objItem.VariableValue
'wscript.echo OraclePath
Found=True
   end if
End If
Next

'code added to update tnsnames.ora during failover and failback
'Set WshShell = WScript.CreateObject("WScript.Shell")
'Set WshEnv = WshShell.Environment("SYSTEM")

strReadFile=""
strWriteFile=""
strReadFile =  OraclePath & "\network\admin\tnsnames.ora"
strWriteFile=OraclePath & "\network\admin\tnsnames_temp.ora"
strVirtualIP=OtherNode
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objWriteTextFile = objFSO.CreateTextFile(strWriteFile,true)

Set objReadTextFile = objFSO.OpenTextFile(strReadFile,1,True)
Set objWriteTextFile = objFSO.OpenTextFile(strWriteFile,8,True)

' Writes strText every time you run this VBScript
Do Until objReadTextFile.AtEndOfStream
strText = objReadTextFile.Readline
if Trim(UCase(strText)) = "CONFDB =" then
     objWriteTextFile.WriteLine("CONFDB =")
objWriteTextFile.WriteLine("  (DESCRIPTION =")
objWriteTextFile.WriteLine("    (ADDRESS_LIST =")
objWriteTextFile.WriteLine("      (ADDRESS = (PROTOCOL = TCP)(Host = " & strVirtualIP & ")(PORT = 1521))")
objWriteTextFile.WriteLine("    )")
objWriteTextFile.WriteLine("  (CONNECT_DATA =")
objWriteTextFile.WriteLine("      (SERVER = DEDICATED)")
objWriteTextFile.WriteLine("    (SID = CONFDB)")
objWriteTextFile.WriteLine("  )")
objWriteTextFile.WriteLine(" )")
objWriteTextFile.WriteLine("MASTERDB =")
objWriteTextFile.WriteLine("  (DESCRIPTION =")
objWriteTextFile.WriteLine("    (ADDRESS_LIST =")
objWriteTextFile.WriteLine("      (ADDRESS = (PROTOCOL = TCP)(Host = " & strVirtualIP & ")(PORT = 1521))")
objWriteTextFile.WriteLine("    )")
objWriteTextFile.WriteLine("  (CONNECT_DATA =")
objWriteTextFile.WriteLine("      (SERVER = DEDICATED)")
objWriteTextFile.WriteLine("    (SID = masterdb)")
objWriteTextFile.WriteLine("  )")
objWriteTextFile.WriteLine(" )")
exit do
else
objWriteTextFile.WriteLine(strText)
end if
Loop
objReadTextFile.Close
objWriteTextFile.Close

objFSO.DeleteFile(strReadFile)

objFSO.MoveFile strWriteFile,strReadFile

strReadFile =  OraclePath32 & "\network\admin\tnsnames.ora"
strWriteFile=OraclePath32 & "\network\admin\tnsnames_temp.ora"

Set objReadTextFile = objFSO.OpenTextFile(strReadFile,1,True)
Set objWriteTextFile = objFSO.OpenTextFile(strWriteFile,8,True)

' Writes strText every time you run this VBScript
Do Until objReadTextFile.AtEndOfStream
strText = objReadTextFile.Readline
if Trim(UCase(strText)) = "CONFDB =" then
     objWriteTextFile.WriteLine("CONFDB =")
objWriteTextFile.WriteLine("  (DESCRIPTION =")
objWriteTextFile.WriteLine("    (ADDRESS_LIST =")
objWriteTextFile.WriteLine("      (ADDRESS = (PROTOCOL = TCP)(Host = " & strVirtualIP & ")(PORT = 1521))")
objWriteTextFile.WriteLine("    )")
objWriteTextFile.WriteLine("  (CONNECT_DATA =")
objWriteTextFile.WriteLine("      (SERVER = DEDICATED)")
objWriteTextFile.WriteLine("    (SID = CONFDB)")
objWriteTextFile.WriteLine("  )")
objWriteTextFile.WriteLine(" )")
objWriteTextFile.WriteLine("MASTERDB =")
objWriteTextFile.WriteLine("  (DESCRIPTION =")
objWriteTextFile.WriteLine("    (ADDRESS_LIST =")
objWriteTextFile.WriteLine("      (ADDRESS = (PROTOCOL = TCP)(Host = " & strVirtualIP & ")(PORT = 1521))")
objWriteTextFile.WriteLine("    )")
objWriteTextFile.WriteLine("  (CONNECT_DATA =")
objWriteTextFile.WriteLine("      (SERVER = DEDICATED)")
objWriteTextFile.WriteLine("    (SID = masterdb)")
objWriteTextFile.WriteLine("  )")
objWriteTextFile.WriteLine(" )")
exit do
else
objWriteTextFile.WriteLine(strText)
end if
Loop
objReadTextFile.Close
objWriteTextFile.Close

objFSO.DeleteFile(strReadFile)

objFSO.MoveFile strWriteFile,strReadFile

set objFSO = NOTHING
'code added to update tnsnames.ora during ailover and failback


End Function
'*********************************Offline Function****************************

'*********************************Online Function****************************
'Descriotion: updates tnsnames.ora with the computer name of system
'brings online database services on system where script is triggered
'brings all the application services (prep,pass,insert,ais) online by calling ApplicationFailoverFailback on the system where the applcation services are running (it can be same server or the other server)
Function Online()



strComputer = "."
Set objWMIService = GetObject( _
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery( _
    "Select * from Win32_Environment ")
Found = False
For Each objItem in colItems
if Found=False then
    If objItem.Name = "ORACLE_HOME" Then
    OraclePath=objItem.VariableValue
'wscript.echo OraclePath
Found=True
    end if
    End If
Next

Found = False
For Each objItem in colItems
if Found=False then
    If objItem.Name = "ORACLE_HOME_32" Then
    OraclePath32=objItem.VariableValue
Found=True
    end if
    End If
Next

set objWMIService =NOTHING
'code added to update tnsnames.ora during failover and failback
'Set WshShell = WScript.CreateObject("WScript.Shell")
'Set WshEnv = WshShell.Environment("SYSTEM")
strReadFile=""
strWriteFile=""
strReadFile =  OraclePath & "\network\admin\tnsnames.ora"
strWriteFile=OraclePath & "\network\admin\tnsnames_temp.ora"

strVirtualIP=myNode  
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objWriteTextFile = objFSO.CreateTextFile(strWriteFile,true)

Set objReadTextFile = objFSO.OpenTextFile(strReadFile,1,True)
Set objWriteTextFile = objFSO.OpenTextFile(strWriteFile,8,True)



' Writes strText every time you run this VBScript
Do Until objReadTextFile.AtEndOfStream
strText = objReadTextFile.Readline
if Trim(UCase(strText)) = "CONFDB =" then
     objWriteTextFile.WriteLine("CONFDB =")
objWriteTextFile.WriteLine("  (DESCRIPTION =")
objWriteTextFile.WriteLine("    (ADDRESS_LIST =")
objWriteTextFile.WriteLine("      (ADDRESS = (PROTOCOL = TCP)(Host = " & strVirtualIP & ")(PORT = 1521))")
objWriteTextFile.WriteLine("    )")
objWriteTextFile.WriteLine("  (CONNECT_DATA =")
objWriteTextFile.WriteLine("      (SERVER = DEDICATED)")
objWriteTextFile.WriteLine("    (SID = CONFDB)")
objWriteTextFile.WriteLine("  )")
objWriteTextFile.WriteLine(" )")
objWriteTextFile.WriteLine("MASTERDB =")
objWriteTextFile.WriteLine("  (DESCRIPTION =")
objWriteTextFile.WriteLine("    (ADDRESS_LIST =")
objWriteTextFile.WriteLine("      (ADDRESS = (PROTOCOL = TCP)(Host = " & strVirtualIP & ")(PORT = 1521))")
objWriteTextFile.WriteLine("    )")
objWriteTextFile.WriteLine("  (CONNECT_DATA =")
objWriteTextFile.WriteLine("      (SERVER = DEDICATED)")
objWriteTextFile.WriteLine("    (SID = masterdb)")
objWriteTextFile.WriteLine("  )")
objWriteTextFile.WriteLine(" )")
exit do
else
objWriteTextFile.WriteLine(strText)
end if
Loop
objReadTextFile.Close
objWriteTextFile.Close

objFSO.DeleteFile(strReadFile)

objFSO.MoveFile strWriteFile,strReadFile

strReadFile =  OraclePath32 & "\network\admin\tnsnames.ora"
strWriteFile=OraclePath32 & "\network\admin\tnsnames_temp.ora"

Set objReadTextFile = objFSO.OpenTextFile(strReadFile,1,True)
Set objWriteTextFile = objFSO.OpenTextFile(strWriteFile,8,True)

' Writes strText every time you run this VBScript
Do Until objReadTextFile.AtEndOfStream
strText = objReadTextFile.Readline
if Trim(UCase(strText)) = "CONFDB =" then
     objWriteTextFile.WriteLine("CONFDB =")
objWriteTextFile.WriteLine("  (DESCRIPTION =")
objWriteTextFile.WriteLine("    (ADDRESS_LIST =")
objWriteTextFile.WriteLine("      (ADDRESS = (PROTOCOL = TCP)(Host = " & strVirtualIP & ")(PORT = 1521))")
objWriteTextFile.WriteLine("    )")
objWriteTextFile.WriteLine("  (CONNECT_DATA =")
objWriteTextFile.WriteLine("      (SERVER = DEDICATED)")
objWriteTextFile.WriteLine("    (SID = CONFDB)")
objWriteTextFile.WriteLine("  )")
objWriteTextFile.WriteLine(" )")
objWriteTextFile.WriteLine("MASTERDB =")
objWriteTextFile.WriteLine("  (DESCRIPTION =")
objWriteTextFile.WriteLine("    (ADDRESS_LIST =")
objWriteTextFile.WriteLine("      (ADDRESS = (PROTOCOL = TCP)(Host = " & strVirtualIP & ")(PORT = 1521))")
objWriteTextFile.WriteLine("    )")
objWriteTextFile.WriteLine("  (CONNECT_DATA =")
objWriteTextFile.WriteLine("      (SERVER = DEDICATED)")
objWriteTextFile.WriteLine("    (SID = masterdb)")
objWriteTextFile.WriteLine("  )")
objWriteTextFile.WriteLine(" )")
exit do
else
objWriteTextFile.WriteLine(strText)
end if
Loop
objReadTextFile.Close
objWriteTextFile.Close

objFSO.DeleteFile(strReadFile)

objFSO.MoveFile strWriteFile,strReadFile

set objFSO = NOTHING
'code added to update tnsnames.ora during ailover and failback

'servername = "localhost"
servername = "SEP03VVM409"
set objWMIService = getobject("winmgmts://" & servername)

ServiceName = "OracleOraDb11g_home1TNSListener"
wql = "select state from win32_service " _
               & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results

  if service.state = "Stopped" then
    service.StartService
  end if
next


blnServiceStarted = "false"
Do While blnServiceStarted = "false"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results
  if service.state = "Running" then
     blnServiceStarted = "true"    
  end if
next
loop
ServiceName = "OracleServiceCONFDB"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results
  if service.state = "Stopped" then
     service.StartService
   end if
next


blnServiceStarted = "false"
Do While blnServiceStarted = "false"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results

  if service.state = "Running" then
     blnServiceStarted = "true" 
  else
     WScript.Sleep 4000 
  end if
next
loop
ServiceName = "OracleServicemasterdb"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results
  if service.state = "Stopped" then
     service.StartService
   end if
next


blnServiceStarted = "false"
Do While blnServiceStarted = "false"
wql = "select state from win32_service " _
           & "where displayname='"& ServiceName & "'"
set results = objWMIService.execquery(wql)
for each service in results
  if service.state = "Running" then
     blnServiceStarted = "true"   
  else
     WScript.Sleep 4000 
  end if
next
loop

Set oShell  = CreateObject("WScript.Shell")
appCmd      = "cluster resource ApplicationFailoverFailback /online"
oShell.Run appCmd, 4, false
set oShell = NOTHING


Online = true
End Function
'*********************************Online Function****************************

'*********************************LooksAlive Function****************************
Function LooksAlive()
LooksAlive = true
End Function
'*********************************LooksAlive Function****************************

'*********************************isAlive Function****************************
Function IsAlive()
IsAlive = true
End Function
'*********************************isAlive Function****************************

'*********************************Close Function****************************
Function IsAlive()
IsAlive = true
End Function

Function Open()
Open = 0
End Function

Function Close()
Close = 0
End Function

Function Terminate()
Terminate = 0
End Function
'*********************************Close Function****************************

Viewing all articles
Browse latest Browse all 5654

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>