Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round 2 - rolling server restart.

Status
Not open for further replies.

sparkbyte

Technical User
Sep 20, 2002
879
US
OK, I am back on this project. I am completey stumpted as to how to reboot a group of servers and then make sure some services start before moving on to the next group of servers.

I have worked out how to check and start the needed services, so it this point I need some idea's and maybe an example of how to track to progression of the servers.

Thanks....

Thanks

John Fuhrman
Titan Global Services
 
Well...not tested...but maybe

Code:
Option Explicit

ServerReboot

Sub ServerReboot
	Dim arrServers : arrServers = Array("server1", "server2", "server3")
	Dim strServer
	For Each strServer In arrServers
		Reboot strServer
		CheckServices strServer
	Next
End Sub

Sub Reboot(strServer)
	'code to reboot server
	' wait until server is no longer reachable via ping
	Do While Reachable(strServer)
		WScript.Sleep 5000
	Loop
	
	' wait until server is reachable via ping
	Do While Not Reachable(strServer)
		WScript.Sleep 5000
	Loop
	
	WScript.Sleep 60000
End Sub

Sub CheckServices(strServer)
	Dim strWQL : strWQL = "Select * From Win32_Service Where Name Like 'SynSrv_%' " & _
	                      "And StartMode='Auto'"
	Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & strServer & "\root\cimv2")
	Dim colServices : Set colServices = objWMIService.ExecQuery(strWQL)
	Dim intCount : intCount = colServices.Count
	Dim serviceItem
	Do Until intCount = 0
	    Set colServices = objWMIService.ExecQuery(strWQL)
	    For Each serviceItem In colServices
	        Select Case UCase(serviceItem.State)
	            Case "RUNNING"
	                intCount = intCount - 1
	            Case "STOPPED"
	                serviceItem.StartService()
	        End Select
	    Next
	    WScript.Sleep 5000
	Loop
End Sub

Function Reachable(strComputer)
	Dim wmiQuery : wmiQuery = "Select * From Win32_PingStatus Where Address = '" & _
							  strComputer & "'"
	Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
	Dim objPing : Set objPing = objWMIService.ExecQuery(wmiQuery)
	Dim objStatus
	For Each objStatus in objPing
		If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
			Reachable = False
		Else
			Reachable = True
		End If
	Next
End Function

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Wow that was fast!!! And it shows me I was trying to make this far to complicated.

My idea was to create a dictionary table with a list of servers plus a couple of additional properties and toggle the properties on each server entry in the dictionary table as each task was completed. Needless to say I found myself getting lost rather quickly.

Thanks dm4ever!!!! It's Dave right??
I can't begin to tell you (and several others) how much I value your expertise. You have shown/taught me quite a bit over the past few months!!


Thanks

John Fuhrman
Titan Global Services
 
Oh man....some more sleep please....so sleepy....zzzzz

Using a dictionary would let you carry around more info in a convenient manner. It really depends on your need.

It's not Dave...dm_4ever is something I came up when I was in the Marine Corps and its meaning is lost to me now...

Thanks for the kind words.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top