Guest User

[BATCH] DHCP Failover/Watchdog v1.2b

a guest
Sep 16th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. :: Purpose:         DHCP server Watchdog & Failover script. Read notes below
  2. :: Requirements:    1. Domain administrator credentials & "Logon as a batch job" rights
  3. ::                  2. Proper firewall configuration to allow connection
  4. ::                  3. Proper permissions on the DHCP backup directory
  5. :: Author:          vocatus on reddit.com/r/usefulscripts
  6. :: Version:         1.2b + Added comment block explaining syntax rules for variables
  7. ::                  1.2  + Added functionality to recover the DHCP database BACK to the primary server after a failure. Now when the backup server detects that
  8. ::                         the primary server has come back online after an outage, it will export its current copy of the DHCP database, upload it back to the
  9. ::                         primary server, import it, and spin it back up using the most recent copy. This addresses the issue of new leases being passed out during
  10. ::                         an outage of the primary server and it not being aware of those leases when it comes back online.
  11. ::                       + Added "REMOTE_OPERATIING_PATH" variable that lets us specify where the remote server keeps its DHCP working files during operation
  12. ::                       + Added "UPDATED" variable to note when the script was last updated
  13. ::                  1.1c + Added quotes around all variables that could contain paths
  14. ::                       + Added full path to SC.exe to prevent failure in the event %PATH% gets corrupted or mangled (this happened in testing)
  15. ::                       * Fixed a glitch that could occur when pinging an assumed-down primary server that would incorrectly think it was back up
  16. ::                       - Removed almost every entry of "2>&1" since it's really not needed
  17. ::                  1.1b - Changed DATE to CUR_DATE format to be consistent with all other scripts
  18. ::                  1.1  - Comments improvement
  19. ::                       / Tuned some parameters (ping count on checking)
  20. ::                       / Some logging tweaks
  21. ::                       / Renamed FAILOVER_DELAY to FAILOVER_RECHECK_DELAY for clarity
  22. ::                  1.0d * Some logging tweaks
  23. ::                  1.0c * Some logging tweaks
  24. ::                  1.0 Initial write
  25. :: Notes:           I wrote this script after failing to find a satisfactory method of performing
  26. ::                  watchdog/failover between two Windows Server 2008 R2 DHCP servers.
  27. ::                
  28. :: Use:             This script has two modes: "Watchdog" and "Failover."
  29. ::                  - Watchdog checks the status of the remote DHCP service, logs it, and then grabs the remote DHCP db backup file and imports it.
  30. ::                  - Failover mode is activated when the script cannot determine the status of the remote DHCP server. The script then activates
  31. ::                    the local DHCP server with the latest backup copy it successfully retrieved from the primary server.
  32. ::                  
  33. :: Instructions:
  34. ::                  1. Tune the variables in this script to your desired backup location and frequency
  35. ::                  2. On the primary server: set the DHCP backup interval to your desired backup frequency. The value is in minutes; I recommend 5 minutes.
  36. ::                     You do this by modifying this registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DHCPServer\Parameters\BackupInterval
  37. ::                  3. On the backup server:  set this script to run as a scheduled task. I recommend every 10 minutes.
  38. :: Notice:
  39. ::                 !! Make sure to set it only to run if it isn't already running! If there is a failover you could have
  40. ::                    Task Scheduler spawn a new instance of the script every n minutes and end up with hundreds of copies
  41. ::                    of this script running.
  42.  
  43.  
  44. :: Prep
  45. SETLOCAL
  46. @echo off
  47. cls
  48. set VERSION=1.2b
  49. set UPDATED=2013-09-16
  50. title [DHCP Server Watchdog v%VERSION%]
  51.  
  52.  
  53. :::::::::::::::
  54. :: VARIABLES :: - Set these
  55. :::::::::::::::
  56. :: Rules for variables:
  57. ::  * NO quotes!                       (bad:  "c:\directory\path"       )
  58. ::  * NO trailing slashes on the path! (bad:   c:\directory\            )
  59. ::  * Spaces are okay                  (okay:  c:\my folder\with spaces )
  60. ::  * Network paths are okay           (okay:  \\server\share name      )
  61. ::                                     (       \\172.16.1.5\share name  )
  62.  
  63. :: Remote server is the PRIMARY DHCP server we're watching. Use a hostname or IP address.
  64. set REMOTE_SERVER=mikado
  65.  
  66. :: Location of the automatic DHCP backup file on the primary server. Windows generates this automatically.
  67. :: Best practice is to leave this alone, unless you have a custom backup location.
  68. :: The script builds the backup line like this: \\%REMOTE_SERVER%\c$\%REMOTE_BACKUP_PATH%
  69. set REMOTE_BACKUP_PATH=Windows\system32\dhcp\backup
  70.  
  71. :: Location of the operational DHCP database files on the remote (primary) server.
  72. :: Best practice is to leave this alone, unless you have a custom location. Changing this will break the
  73. :: function that re-uploads the most current db back to the primary server after a failure. This doesn't
  74. :: ruin the script, but if the backup server passed out any IP's while the primary server was down, the
  75. :: primary server won't know about them when it comes back up.
  76. set REMOTE_OPERATING_PATH=Windows\system32\dhcp
  77.  
  78. :: Location of your backup/standby file. I normally copy directly to my backup server's DHCP directory.
  79. :: The script builds the local backup line like this: c:\windows\system32\dhcp\[backup folders]
  80. set LOCAL_BACKUP_PATH=%SystemRoot%\system32\dhcp
  81.  
  82. :: When a failover is triggered, how many seconds should we wait in between each attempt to contact the primary server again?
  83. set FAILOVER_RECHECK_DELAY=15
  84.  
  85. :: Log options. Don't put an extension on the log file name. (Important!) The script sets this later on.
  86. set LOGPATH=%SystemDrive%\Logs
  87. set LOGFILE=%COMPUTERNAME%_DHCP_watchdog
  88.  
  89. :: Max log file size allowed (in bytes) before rotation and archive. I recommend setting this to 2 MB (2097152).
  90. :: Example: 524288 is half a megabyte (~500KB)
  91. set LOG_MAX_SIZE=10485760
  92.  
  93. :: \/ Don't touch anything below this line. If you do, you will break something.
  94. set CUR_DATE=%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%
  95.  
  96.  
  97. :::::::::::::::::::::::
  98. :: LOG FILE HANDLING :: - This section handles the log file
  99. :::::::::::::::::::::::
  100.  
  101. :: Make the logfile if it doesn't exist
  102. if not exist %LOGPATH% mkdir %LOGPATH%
  103. if not exist %LOGPATH%\%LOGFILE%.log goto new_log
  104.  
  105. :: Check log size. If it hasn't exceeded our size limit, jump straight to Watchdog mode
  106. for %%R in (%LOGPATH%\%LOGFILE%.log) do if %%~zR LSS %LOG_MAX_SIZE% goto newrun
  107.  
  108. :: However, if the log was too big, go ahead and rotate it.
  109. pushd %LOGPATH%
  110. del %LOGFILE%.ancient 2>NUL
  111. rename %LOGFILE%.oldest %LOGFILE%.ancient 2>NUL
  112. rename %LOGFILE%.older %LOGFILE%.oldest 2>NUL
  113. rename %LOGFILE%.old %LOGFILE%.older 2>NUL
  114. rename %LOGFILE%.log %LOGFILE%.old 2>NUL
  115. popd
  116.  
  117. :: And then create the header for the new log file
  118. :new_log
  119. echo ------------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%.log
  120. echo  Initializing new DHCP Server Watchdog log on %CUR_DATE% at %TIME%, max log size %LOG_MAX_SIZE% bytes>> %LOGPATH%\%LOGFILE%.log
  121. echo ------------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%.log
  122. echo.>> %LOGPATH%\%LOGFILE%.log
  123.  
  124. :: New run section - if we just launched the script, write a header for this run
  125. :newrun
  126. echo ------------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%.log
  127. echo  DHCP Server Watchdog v%VERSION%, %CUR_DATE%>> %LOGPATH%\%LOGFILE%.log
  128. echo   Running as %USERDOMAIN%\%USERNAME% on %COMPUTERNAME%>> %LOGPATH%\%LOGFILE%.log
  129. echo.>> %LOGPATH%\%LOGFILE%.log
  130. echo  Job Options>> %LOGPATH%\%LOGFILE%.log
  131. echo   Log location:            %LOGPATH%\%LOGFILE%.log>> %LOGPATH%\%LOGFILE%.log
  132. echo   Log max size:            %LOG_MAX_SIZE% bytes>> %LOGPATH%\%LOGFILE%.log
  133. echo   Watching primary server: %REMOTE_SERVER%>> %LOGPATH%\%LOGFILE%.log
  134. echo   Mirroring this DHCP db:  %REMOTE_BACKUP_PATH%>> %LOGPATH%\%LOGFILE%.log
  135. echo   Local backup location:   %LOCAL_BACKUP_PATH%>> %LOGPATH%\%LOGFILE%.log
  136. echo ------------------------------------------------------------------------------------->> %LOGPATH%\%LOGFILE%.log
  137. echo %CUR_DATE% %TIME%         Starting Watchdog mode.>> %LOGPATH%\%LOGFILE%.log
  138. echo.
  139. echo  DHCP Server Watchdog v%VERSION%
  140. echo   Running as: %USERDOMAIN%\%USERNAME% on %COMPUTERNAME%
  141. echo   Log:        %LOGPATH%\%LOGFILE%.log
  142.  
  143.  
  144. :::::::::::::::::::
  145. :: WATCHDOG MODE ::
  146. :::::::::::::::::::
  147. :watchdog
  148.  
  149. :: Ping the server to see if it's up
  150. echo.
  151. echo   Verifying proper operation of DHCP server on %REMOTE_SERVER%, please wait...
  152. echo.
  153. echo %CUR_DATE% %TIME%         Pinging %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
  154. echo %CUR_DATE% %TIME%         Pinging %REMOTE_SERVER%...
  155. ping %REMOTE_SERVER% -n %FAILOVER_RECHECK_DELAY% >NUL
  156. if %ERRORLEVEL%==1 echo %CUR_DATE% %TIME% WARNING %REMOTE_SERVER% failed to respond to ping. && echo %CUR_DATE% %TIME% WARNING %REMOTE_SERVER% failed to respond to ping.>> %LOGPATH%\%LOGFILE%.log
  157. if not %ERRORLEVEL%==1 echo %CUR_DATE% %TIME% SUCCESS %REMOTE_SERVER% responded to ping. && echo %CUR_DATE% %TIME% SUCCESS %REMOTE_SERVER% responded to ping.>> %LOGPATH%\%LOGFILE%.log
  158.  
  159. :: Check & Log
  160. echo %CUR_DATE% %TIME%         Checking DHCP server status on %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
  161. echo %CUR_DATE% %TIME%         Checking DHCP server status on %REMOTE_SERVER%...
  162.  
  163. :: Reset ERRORLEVEL back to 0
  164. ver > NUL
  165.  
  166. :: Use "SC" to check the status of "Dhcpserver" service, find the "RUNNING" state, and act accordingly based on the return code
  167. %WINDIR%\System32\sc.exe \\%REMOTE_SERVER% query Dhcpserver | find "RUNNING" >NUL
  168. if %ERRORLEVEL%==0 echo %CUR_DATE% %TIME% SUCCESS The DHCP service is running on %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
  169. if %ERRORLEVEL%==0 echo %CUR_DATE% %TIME% SUCCESS The DHCP service is running on %REMOTE_SERVER%.
  170.  
  171. :: This section only executes if the test failed.
  172. if not %ERRORLEVEL%==0 (
  173.     echo %CUR_DATE% %TIME% FAILURE The DHCP service is not running on %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
  174.     echo %CUR_DATE% %TIME%         Activating failover procedure. Local DHCP server will be initialized using most recent successful backup.>> %LOGPATH%\%LOGFILE%.log
  175.     echo %CUR_DATE% %TIME% FAILURE The DHCP service is not running on %REMOTE_SERVER%.
  176.     echo %CUR_DATE% %TIME%         Activating failover procedure. Local DHCP server will be initialized using most recent successful backup.
  177.     goto failover
  178.     )
  179.  
  180. :: Reset ERRORLEVEL back to 0
  181. ver > NUL
  182.  
  183. :: Fetch
  184. echo %CUR_DATE% %TIME%         Fetching DHCP database backup from %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
  185. echo %CUR_DATE% %TIME%         Fetching DHCP database backup from %REMOTE_SERVER%...
  186. xcopy "\\%REMOTE_SERVER%\c$\%REMOTE_BACKUP_PATH%\*" "%LOCAL_BACKUP_PATH%\backup_new_pending\" /E /Y /Q >NUL
  187.  
  188. :: If the copy SUCCEEDED, this executes
  189. if %ERRORLEVEL%==0 (
  190.     echo %CUR_DATE% %TIME% SUCCESS Backup fetched from %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
  191.     echo %CUR_DATE% %TIME% SUCCESS Backup fetched from %REMOTE_SERVER%.
  192.     echo %CUR_DATE% %TIME%         Rotating database backups...>> %LOGPATH%\%LOGFILE%.log
  193.     echo %CUR_DATE% %TIME%         Rotating database backups...
  194.     :: Rotate backups and use newest copy
  195.     rmdir /S /Q %LOCAL_BACKUP_PATH%\backup5
  196.     if exist "%LOCAL_BACKUP_PATH%\backup4" move /Y "%LOCAL_BACKUP_PATH%\backup4" "%LOCAL_BACKUP_PATH%\backup5"
  197.     if exist "%LOCAL_BACKUP_PATH%\backup3" move /Y "%LOCAL_BACKUP_PATH%\backup3" "%LOCAL_BACKUP_PATH%\backup4"
  198.     if exist "%LOCAL_BACKUP_PATH%\backup2" move /Y "%LOCAL_BACKUP_PATH%\backup2" "%LOCAL_BACKUP_PATH%\backup3"
  199.     if exist "%LOCAL_BACKUP_PATH%\backup" move /Y "%LOCAL_BACKUP_PATH%\backup" "%LOCAL_BACKUP_PATH%\backup2"
  200.     move /Y "%LOCAL_BACKUP_PATH%\backup_new_pending" "%LOCAL_BACKUP_PATH%\backup" >NUL
  201.     echo %CUR_DATE% %TIME%         Database backups rotated.>> %LOGPATH%\%LOGFILE%.log
  202.     echo %CUR_DATE% %TIME%         Database backups rotated.
  203.     )
  204.  
  205. :: If the copy FAILED, this executes:
  206. if not %ERRORLEVEL%==0 (
  207.     echo %CUR_DATE% %TIME% WARNING There was an error copying the backup from %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
  208.     echo %CUR_DATE% %TIME%         You may want to look into this since we were able to check the DHCPserver service status but the file copy failed.>> %LOGPATH%\%LOGFILE%.log
  209.     echo %CUR_DATE% %TIME%         Skipping new database import due to copy failure.>> %LOGPATH%\%LOGFILE%.log
  210.     echo %CUR_DATE% %TIME%         Job complete with errors.>> %LOGPATH%\%LOGFILE%.log
  211.     echo %CUR_DATE% %TIME% WARNING There was an error copying the backup from %REMOTE_SERVER%.
  212.     echo %CUR_DATE% %TIME%         You may want to look into this since we were able to check the DHCPserver service status but the file copy failed.
  213.     echo %CUR_DATE% %TIME%         Skipping new database import due to copy failure.
  214.     echo %CUR_DATE% %TIME%         Job complete with errors.
  215.     )
  216.    
  217. :: Import database
  218. echo %CUR_DATE% %TIME%         Starting local DHCP server to import new database...>> %LOGPATH%\%LOGFILE%.log
  219. echo %CUR_DATE% %TIME%         Starting local DHCP server to import new database...
  220.     net start Dhcpserver
  221. echo %CUR_DATE% %TIME%         Local DHCP server running. Performing import...>> %LOGPATH%\%LOGFILE%.log
  222. echo %CUR_DATE% %TIME%         Local DHCP server running. Performing import...
  223.     netsh dhcp server restore "%LOCAL_BACKUP_PATH%\backup"
  224. echo %CUR_DATE% %TIME%         Import complete.>> %LOGPATH%\%LOGFILE%.log
  225. echo %CUR_DATE% %TIME%         Import complete.
  226. echo %CUR_DATE% %TIME%         Stopping local DHCP server...>> %LOGPATH%\%LOGFILE%.log
  227. echo %CUR_DATE% %TIME%         Stopping local DHCP server...
  228.     sc stop Dhcpserver
  229. echo %CUR_DATE% %TIME%         Local DHCP server stopped.>> %LOGPATH%\%LOGFILE%.log
  230. echo %CUR_DATE% %TIME%         Local DHCP server stopped.
  231. echo %CUR_DATE% %TIME% SUCCESS Job complete, DHCP database backed up and ready for use. Exiting.>> %LOGPATH%\%LOGFILE%.log
  232. echo %CUR_DATE% %TIME% SUCCESS Job complete, DHCP database backed up and ready for use. Exiting.
  233. goto EOF
  234.  
  235.  
  236. :::::::::::::::::::
  237. :: FAILOVER MODE ::
  238. :::::::::::::::::::
  239.  
  240. :failover
  241. :: Log this AND display to console
  242. echo %CUR_DATE% %TIME% WARNING Failover activated.>> %LOGPATH%\%LOGFILE%.log
  243. echo %CUR_DATE% %TIME%         Starting local DHCP server using most recent successful backup...>> %LOGPATH%\%LOGFILE%.log
  244. echo.
  245. echo %CUR_DATE% %TIME% WARNING Could not contact primary DHCP server %REMOTE_SERVER%. Failover activated.
  246. echo %CUR_DATE% %TIME%         Starting local DHCP server using most recent successful backup...
  247. echo.
  248.     net start Dhcpserver
  249. echo %CUR_DATE% %TIME%         Local DHCP server started.>> %LOGPATH%\%LOGFILE%.log
  250. echo %CUR_DATE% %TIME%         Entering monitoring loop. Checking if %REMOTE_SERVER% is back up every %FAILOVER_RECHECK_DELAY% seconds...>> %LOGPATH%\%LOGFILE%.log
  251. echo %CUR_DATE% %TIME%         Local DHCP server started.
  252. echo %CUR_DATE% %TIME%         Entering monitoring loop. Checking if %REMOTE_SERVER% is back up every %FAILOVER_RECHECK_DELAY% seconds...
  253.  
  254.  
  255. :failover_loop
  256. :: First we ping the server
  257. ping %REMOTE_SERVER% -n 5 >NUL
  258. :: If no ping response, this section executes
  259. IF NOT %ERRORLEVEL%==0 (
  260.     echo %CUR_DATE% %TIME% FAILURE No ping response from %REMOTE_SERVER%. Waiting %FAILOVER_RECHECK_DELAY% seconds to check again.>> %LOGPATH%\%LOGFILE%.log
  261.     echo %CUR_DATE% %TIME% FAILURE No ping response from %REMOTE_SERVER%. Waiting %FAILOVER_RECHECK_DELAY% seconds to check again.
  262.     ping localhost -n %FAILOVER_RECHECK_DELAY% >NUL
  263.     goto failover_loop
  264.     )
  265.  
  266. :: If yes ping response, this section executes
  267. :: This declaration is required to get the nested IF ERRORLEVEL test to function correctly
  268. SETLOCAL ENABLEDELAYEDEXPANSION
  269. if not %ERRORLEVEL%==1 (
  270.     echo %CUR_DATE% %TIME% NOTICE  %REMOTE_SERVER% is responding to pings.>> %LOGPATH%\%LOGFILE%.log
  271.     echo %CUR_DATE% %TIME% NOTICE  %REMOTE_SERVER% is responding to pings.
  272.     echo %CUR_DATE% %TIME%         Checking DHCP server status on %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
  273.     echo %CUR_DATE% %TIME%         Checking DHCP server status on %REMOTE_SERVER%...
  274.    
  275.     :: This section checks to see if the Dhcpserver service is back up and acts accordingly
  276.     %WINDIR%\System32\sc.exe \\%REMOTE_SERVER% query Dhcpserver | find "RUNNING" >NUL
  277.         :: The exclamation points around ERRORLEVEL here prevent it from incorrectly being expanded using the external ERRORLEVEL results from the first IF statement
  278.         if !ERRORLEVEL!==0 (
  279.                 echo %CUR_DATE% %TIME% SUCCESS The DHCP service is running on %REMOTE_SERVER%.>> %LOGPATH%\%LOGFILE%.log
  280.                 echo %CUR_DATE% %TIME% SUCCESS The DHCP service is running on %REMOTE_SERVER%.
  281.                 echo %CUR_DATE% %TIME%         Primary DHCP server %REMOTE_SERVER% is back up. Beginning recovery procedures...>> %LOGPATH%\%LOGFILE%.log
  282.                 echo %CUR_DATE% %TIME%         Primary DHCP server %REMOTE_SERVER% is back up. Beginning recovery procedures...
  283.                
  284.                 :: Back up the database that we've been running temporarily while the primary server was down
  285.                 echo %CUR_DATE% %TIME%         Exporting the current DHCP database...>> %LOGPATH%\%LOGFILE%.log
  286.                 echo %CUR_DATE% %TIME%         Exporting the current DHCP database...
  287.                 netsh dhcp server backup %TEMP%\DHCP-RECOVERY
  288.                
  289.                 :: Stop our local server since we're done performing DHCP server duties
  290.                 echo %CUR_DATE% %TIME%         Stopping local DHCP server...>> %LOGPATH%\%LOGFILE%.log
  291.                 echo %CUR_DATE% %TIME%         Stopping local DHCP server...
  292.                 sc stop Dhcpserver
  293.                
  294.                 :: Send the database back to the primary server
  295.                 echo %CUR_DATE% %TIME%         Uploading current DHCP database to %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
  296.                 echo %CUR_DATE% %TIME%         Uploading current DHCP database to %REMOTE_SERVER%...
  297.                 xcopy "%TEMP%\DHCP-RECOVERY\*" "\\%REMOTE_SERVER%\c$\%REMOTE_OPERATING_PATH%\DHCP-RECOVERY\" /S /Y /Q 2>NUL
  298.  
  299.                 :: Import the current database on the primary server
  300.                 echo %CUR_DATE% %TIME%         Importing current DHCP database on %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
  301.                 echo %CUR_DATE% %TIME%         Importing current DHCP database on %REMOTE_SERVER%...
  302.                 netsh dhcp server \\%REMOTE_SERVER% restore "\\%REMOTE_SERVER%\c$\%REMOTE_OPERATING_PATH%\DHCP-RECOVERY"
  303.                 :: force a delay to let it stop
  304.                 ping -n 4 localhost >NUL
  305.                
  306.                 :: Spin the primary server back up. For some reason we have to run the command twice for it to actually start. Don't ask.
  307.                 echo %CUR_DATE% %TIME%         Restarting DHCP server on %REMOTE_SERVER%...>> %LOGPATH%\%LOGFILE%.log
  308.                 echo %CUR_DATE% %TIME%         Restarting DHCP server on %REMOTE_SERVER%...
  309.                 sc \\%REMOTE_SERVER% stop Dhcpserver
  310.                 ping localhost -n 8 >NUL
  311.                 sc \\%REMOTE_SERVER% start Dhcpserver
  312.                 ping localhost -n 5 >NUL
  313.                 sc \\%REMOTE_SERVER% query Dhcpserver
  314.                 ping localhost -n 8 >NUL
  315.                 sc \\%REMOTE_SERVER% start Dhcpserver
  316.                
  317.                 REM :: Check to make sure it's working
  318.                 REM echo %CUR_DATE% %TIME%         Verifying functionality on primary server...>> %LOGPATH%\%LOGFILE%.log
  319.                 REM echo %CUR_DATE% %TIME%         Verifying functionality on primary server...
  320.                 REM sc \\%REMOTE_SERVER% query Dhcpserver | find "RUNNING"
  321.                 REM if not %ERRORLEVEL%==0 echo %CUR_DATE% %TIME% FAILURE DHCP server on %REMOTE_SERVER% is not running. You should investigate this manually.>> %LOGPATH%\%LOGFILE%.log
  322.                 REM if %ERRORLEVEL%==0 echo %CUR_DATE% %TIME% SUCCESS DHCP server on %REMOTE_SERVER% is up and running. Recovery complete.>> %LOGPATH%\%LOGFILE%.log
  323.  
  324.                 :: Clean up
  325.                 rmdir /S /Q %TEMP%\DHCP-RECOVERY
  326.                
  327.                 :: Done.
  328.                 echo %CUR_DATE% %TIME%         Exiting.>> %LOGPATH%\%LOGFILE%.log
  329.                 echo %CUR_DATE% %TIME%         Exiting.
  330.                 goto EOF
  331.                 )
  332.     )
  333. ENDLOCAL
  334.  
  335. :: If the host responds to pings but the DHCP service isn't running, this executes
  336. echo %CUR_DATE% %TIME% FAILURE %REMOTE_SERVER% is responding to pings, but DHCP isn't responding (yet?). Will try again in %FAILOVER_RECHECK_DELAY% seconds.>> %LOGPATH%\%LOGFILE%.log
  337. echo %CUR_DATE% %TIME% FAILURE %REMOTE_SERVER% is responding to pings, but DHCP isn't responding (yet?). Will try again in %FAILOVER_RECHECK_DELAY% seconds.
  338. ver >NUL
  339. goto failover_loop
  340.  
  341. ENDLOCAL
  342. echo.>> %LOGPATH%\%LOGFILE%.log
  343. :EOF
Add Comment
Please, Sign In to add comment