https://stackoverflow.com/questions/1672338/how-to-sleep-for-5-seconds-in-windowss-command-prompt-or-dos
https://stackoverflow.com/questions/3325081/how-to-check-if-a-service-is-running-via-batch-file-and-start-it-if-it-is-not-r
接到一“特殊”需求,每天自动重启Tomcat,每天....,刚热身就被干死重来,我能说什么....
Windows下创建计划任务,执行restart.bat,脚本如下:
@Echo Off
Set ServiceName=Tomcat8
net stop %ServiceName%
net start %ServiceName%
rem wait 30 seconds
ping 127.0.0.1 -n 30 > nul
rem check service state
SC queryex "%ServiceName%"|Find "STATE"|Find /v "RUNNING">Nul&&(
echo %ServiceName% not running
echo Start %ServiceName%
Net start "%ServiceName%">nul||(
Echo "%ServiceName%" wont start
exit /b 1
)
echo "%ServiceName%" started
exit /b 0
)||(
echo "%ServiceName%" working
exit /b 0
)
启动后,等待30秒,查看服务状态,如果没有运行就再启动一次。