我已经编写了批处理文件来停止并启动tomcat服务器,但是如果服务器有很大的负载则会失败。下面是重启的脚本 -
@echo off
set current_date = %DATE%
echo Stopping Apache Tomcat service on + %DATE% >> restart.log
net stop tomcat7 >> restart.log
net start tomcat7 >> restart.log
以下是我重启失败的日志 -
The Apache Tomcat 7.0 Tomcat7 service could not be stopped.
The service is starting or stopping. Please try again later.
我应该在停止/启动之间使用时间延迟还是应该使用强制终止服务器(如果有这样的事情)
答案 0 :(得分:1)
如果服务无法停止,您可以尝试
@echo off
set "current_date=%DATE%" & rem not used!!
>>"restart.log" (
echo Stopping Apache Tomcat service on %DATE%
rem try to stop service. If failed (||) then kill process
net stop tomcat7 2>&1 || (
for /F "usebackq tokens=2 skip=3" %%i in (`tasklist /FI "services eq tomcat7"`) do (
echo Failed to stop. Killing process Id %%i
taskkill /PID %%i /F >NUL 2>&1
)
rem wait 1.5 second
ping 1.1.1.1 -w 1500 -n 1 >NUL
)
net start tomcat7 2>&1
)