Creating Virtual IP control scripts (Windows)
Start
- On the primary VM Server, create a batch file that is named SC_VIP_UP.BAT, and enter the following commands into the file:
[+] Commands for SC_VIP_UP.BAT
@echo off
rem set the following parameter corresponding to your machine configuration
set VirtualIP=<Virtual IP of the Machine>
rem for example VirtualIP=172.24.133.254
set vipMask=<Subnet mask of the Machine>
rem for example vipMask=255.255.255.0
set VirtualInterface=<Name of existing network Interface in which VIP will be created>
rem for example VirtualInterface="Local Area Connection"
set startCount= 0
set EndCount= 20
rem set the path in which log files will be stored
set Logpath= <Specify the path to log files>
rem for example Logpath= C:\Solution_HA\Logs
echo ********************* SC_VIP_UP_start ********************** >> %Logpath%\Takeover_On.log
echo %date% >> %Logpath%\Takeover_On.log
echo %time% >> %Logpath%\Takeover_On.log
echo. >> %Logpath%\Takeover_On.log
rem check if Virtual IP released on paired host and below loop will check up to 20 counts
:start
if %startCount% GTR %EndCount% GOTO end
echo %startCount%
cscript.exe ping.vbs %VirtualIP% //Nologo >> %Logpath%\Takeover_On.log
if not errorlevel 1 goto ready
echo Looping till VIP disable in backup host >> %Logpath%\Takeover_On.log
set /a startCount+=1
timeout 1
goto start
:end
echo. >> %Logpath%\Takeover_On.log
echo VIP is already enabled either in the same host or the paired host >> %Logpath%\Takeover_On.log
goto done
exit
:ready
rem Add VirtualIP
netsh interface ip delete arpcache
netsh interface ip add address name=%VirtualInterface% addr=%VirtualIP% mask=%vipMask% >> %Logpath%\Takeover_On.log
rem check if VirtualIP added succesefully if not do it again
cscript.exe check_ip.vbs localhost %VirtualIP% //Nologo >> %Logpath%\Takeover_On.log
if errorlevel 1 goto done
netsh interface ip delete address name=%VirtualInterface% addr=%VirtualIP% >> %Logpath%\Takeover_On.log
netsh interface ip add address name=%VirtualInterface% addr=%VirtualIP% mask=%vipMask% >> %Logpath%\Takeover_On.log
if errorlevel 1 echo %VirtualIP% not added to %VirtualInterface% >> %Logpath%\Takeover_On.log
:done
echo. >> %Logpath%\Takeover_On.log
echo ********************* SC_VIP_UP_End ********************** >> %Logpath%\Takeover_On.log
- In the batch file, replace the variables indicated by angle brackets with appropriate values.
- On the primary VM Server, create a batch file that is named SC_VIP_DOWN.BAT, and enter the following commands into the file:
[+] Commands for SC_VIP_DOWN.BAT
@echo off
rem set the following parameter corresponding to your machine configuration
set VirtualIP=<Virtual IP of the Machine>
rem for example VirtualIP=172.24.133.254
set VirtualInterface=<Name of existing network Interface in which VIP will be created>
rem for example VirtualInterface="Local Area Connection"
rem set the path in which log files will be stored
set Logpath= <Specify the path to log files>
rem for example Logpath= C:\Solution_HA\Logs
echo ********************* SC_VIP_DOWN_Start ********************** >> %Logpath%\Takeover_Off.log
echo %date% >> %Logpath%\Takeover_Off.log
echo %time% >> %Logpath%\Takeover_Off.log
netsh interface ip delete address name=%VirtualInterface% addr=%VirtualIP% >> %Logpath%\Takeover_Off.log
netsh interface ip delete arpcache
Timeout 10
cscript.exe ping.vbs %VirtualIP% //Nologo >> %Logpath%\Takeover_Off.log
echo %date% >> %Logpath%\Takeover_Off.log
echo %time% >> %Logpath%\Takeover_Off.log
echo ********************* SC_VIP_DOWN_End ********************** >> %Logpath%\Takeover_Off.log
- In the batch file, replace the variables indicated by angle brackets with appropriate values.
- Add the SC_VIP_DOWN script as a task in Task Scheduler and schedule it to execute when the system starts. This disables the VIP by default when the system starts and according to the mode (Primary/Backup) of the application, the VIP will be enabled or disabled by the alarm reaction scripts.
- Copy the MLCMD utility files (mlcmd.exe and mlcmd.exe.manifest files) that are installed with SCS onto the VM Server.
- On the primary VM Server, create an accessory script that is named Ping.vbs, and enter the following commands into the script:
[+] Commands for Ping.vbs
rem ping host and return 1 if ping successful 0 if not
On Error Resume Next
if WScript.Arguments.Count > 0 then
strTarget = WScript.Arguments(0)
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
strPingResults = LCase(objExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
WScript.Echo strTarget & “responded to ping."
wscript.Quit 1
Else
WScript.Echo strTarget & “did not respond to ping."
wscript.Quit 0
End If
Else
WScript.Echo "target is not specified."
wscript.Quit -1
End If
- On the primary VM Server, create an accessory script that is named Check_ip.vbs, and enter the following commands into the script:
[+] Commands for Check_ip.vbs
rem check if IP address (arg0 ) can be found on host (arg1 )
On Error Resume Next
if WScript.Arguments.Count > 0 then
strComputer = WScript.Arguments(0)
targetIPAddress = WScript.Arguments(1)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
WScript.Echo "Computer Name: " & strComputer & " ip " & targetIPAddress
For Each objNicConfig In colNicConfigs
For Each strIPAddress In objNicConfig.IPAddress
If InStr(strIPAddress, targetIPAddress) Then
WScript.Echo targetIPAddress & " is found on " & objNicConfig.Description
wscript.Quit 1
End If
Next
Next
WScript.Echo targetIPAddress & “not found."
wscript.Quit 0
Else
WScript.Echo "target not specified."
wscript.Quit -1
End If
- Place the accessory scripts Ping.vbs and Check_ip.vbs in the same directory as the SC_VIP_UP.BAT and SC_VIP_DOWN.BAT files.
- Repeat the steps in this procedure to create the scripts on the backup VM Server.
End
Next Steps
Testing control scripts
OR
Back to Task Table