[Go] Monitoring Windows services, automatically restart service when service stops

Source: Internet
Author: User

Recently took time to study the Windows and Linux under a service after the automatic restart function, collected some information on the Internet, and tested, here to tidy up. The monitoring of Windows services is described here, and is done by batch processing. This example is an example of monitoring Windows Computer Browser, which is detected every 60 seconds (the interval can be adjusted according to actual needs) and automatically restarted when the discovery service is stopped. The contents of the Autostartservice.bat batch file are as follows

  @echo Offrem defines the cycle interval and monitoring services: Set Secs=60set srvname= "Computer Browser"  echo.echo ========================= ===============echo = =         Query the status of the computer service,     ==echo = =    %secs% seconds per interval to make a query, &N Bsp   ==echo = =     If it is found to be stopped, start immediately.     ==echo ========================================echo.echo This script monitors the services that are:%srvname%echo. if%srvname%. == . Goto end :chkitset svrst=0for/f "tokens=1* delims="%%a in (' net start ') do if/i "%%a%%b" = =%srvname% Set svrst= 1if%svrst% = = 0 net start%srvname%set svrst=rem The following commands are used for inertia, which may cause the CPU to have a single core full load. Ping-n%secs% 127.0.0.1 > Nulgoto chkit :end  Double-click the batch file to run the interface as follows  ==================================== ======         Check the status of your computer service,     = =     60 seconds per interval,     =   + nbsp If it is found to be stopped, it is started immediately.     ==========================================  The service that this script monitors is: "Computer Browser"    if computer After the browser is stopped, the batch is detected and restartedThe service, the interface is as follows ==========================================         Query the status of computer services,     = =   & nbsp Query once every 60 seconds,     = =     Start immediately if it is found to be stopped.     ==========================================  This script monitoring service is: "Computer Browser"  computer Browser The service is starting. Computer Browser Service has started successfully.  

Original: http://www.aixchina.net/home/space.php?uid=20260&do=blog&id=38889

[Go] Monitoring Windows services, automatically restart service when service stops

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.