Reputation: 159
I have written batch file to stop and start tomcat server but when server has huge load sometime if fails. Below is the script for restart-
@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
Below is the log I am getting on failed restart-
The Apache Tomcat 7.0 Tomcat7 service could not be stopped.
The service is starting or stopping. Please try again later.
Should I use time lag between stop/start or should go for force kill server(if there is anything like this)
Upvotes: 2
Views: 1152
Reputation: 1705
If service is not stoppable you may try
@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
)
Upvotes: 1