Script Library

Sample scripts are provided as-is with no warranty of fitness for a particular purpose. These scripts are solely intended to demonstrate techniques for accomplishing common tasks. Additional script logic and error-handling may need to be added to achieve the desired results in your specific environment.


monitor_restart_www.s

Download

This script monitors a local IIS web site and automatically restarts the World Wide Web Publishing Service if the site is unavailable. If restarting the WWW service does not resolve the problem then this script runs a full iisreset /restart

This sample shows how to use LOOPCOUNT and LOOPTO to implement a retry loop that allows a specified number of errors before failure. It also illustrates the use of DOSCMD to restart a service. The script logic was written as a big loop so you can use the Robo-FTP Service Installer to run this script as a Windows Service so it will constantly monitor the local website and automatically restart if the computer is rebooted.

Note: This script must be run by a user account with permission to restart IIS.


  1  ;; Change these values to match your environment
  2  SET local_site_name = "My Local IIS Managed Site"
  3  SET small_file_name = "sitemap.xml"
  4  
  5  :start
  6  ;; Allow 3 failures (per cycle) before taking action.
  7  LOOPCOUNT 3
  8  
  9  ;; Test downloading a small file from the local website.
 10  :test_web_site
 11  FTPLOGON local_site_name
 12  RCVFILE small_file_name
 13  IFERROR= $ERROR_SUCCESS GOTO done
 14  ;; If we reached this line the test failed.
 15  ;; Wait 30 seconds before trying again.
 16  PAUSE /for=30
 17  LOOPTO test_web_site
 18  
 19  ;; If we reached this line the test failed 3 times.
 20  ;; Take action by restarting the WWW service.
 21  DOSCMD 'net stop "World Wide Web Publishing Service"' 
 22  DOSCMD 'net start "World Wide Web Publishing Service"' 
 23  
 24  ;; Reset the failure counter
 25  LOOPCOUNT 3
 26  
 27  ;; Test again after restarting the WWW service.
 28  ;; If it fails 3 more times take action using IISReset.
 29  :post_restart_test
 30  FTPLOGON local_site_name
 31  RCVFILE small_file_name
 32  IFERROR= $ERROR_SUCCESS GOTO done
 33  PAUSE /for=30
 34  LOOPTO post_restart_test
 35  EXEC "iisreset /restart" /timeout=120
 36  
 37  :done
 38  FTPLOGOFF
 39  ;; Wait 5 minutes (300 seconds) between cycles
 40  PAUSE /for=300
 41  GOTO start

Browse complete list of scripts