Automatic Restart Tomcat Windows Script Taskscheduler Daily Weekly Monthly
Automatic Restart Tomcat Windows Script Taskscheduler Daily Weekly Monthly
I'm responsbile for a project environment made up of 3 components which is occasionally dying. Here is
a short raw overview of environment
The Tomcat and Java Standalone application is running on top of Windows 2008 RC2 Standard, the
overall environment is becoming inacessible periodically and in order to solve that the customer decided
to implement a daily Windows server reboot in my opinion this is very bad approach as it is much better
to just set an auto reboot of each of components using few tiny batch scripts and Windows Taskmgr,
however as the customer is king and decided to implement the reboot its their own thing.
However even fter the daily server reboot was set once a week or so the application was becoming
inaccessible and a Tomcat server restart was necessery as a fix.
Finally as a work-around to the issue, I've proposed the logical thing to automatically restart Tomcat
once a day early in morning, here is how Tomcat auto Restart was implemented on the Win server:
First thing is to use the sc command to find out the Tomcat application name:
1 / 10
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
http://www.pc-freak.net/blog
@echo off
sc stop Tomcat7_r2c && sc start Tomcat7_r2c
2 / 10
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
http://www.pc-freak.net/blog
Don't be confused from screenshot that I have Tomcat7_MyApp instead of Tomcat7_r2c, but I made
screenshot in hurry for another app.
Save the file, somewhere (preferrably) in application folder/bin/ it is best to save it once with bat
extension MyApp-Tomcat_Restart.bat and once as MyApp-Tomcat_Restart.xml (XML format file is
later needed for import to Task Scheduler which understands .XMLs). The .bat file is good to have
because it is useful to somtimes restart Tomcat manually by running it (in case of some sudden
Tomcat Appserver occurs even though the auto-restart script).
Task can be created also from command line using following syntax:
3 / 10
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
http://www.pc-freak.net/blog
/XML /TN
Simple way to create a new Windows task is shown in below command, it will set my Tomcat
Restart script to run everyday in 05:00 early morning when no employees are using the system:
4 / 10
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
http://www.pc-freak.net/blog
Alternative way is to use Task Scheduler GUI frontend and create new (Basic Task) or import just
created script
Taskschd.msc
5 / 10
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
http://www.pc-freak.net/blog
To import already existing .XML formatted file for Task scheduler, right click on the Task Scheduler
(Local) and select Import task
6 / 10
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
http://www.pc-freak.net/blog
7 / 10
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
http://www.pc-freak.net/blog
After making all changes you will be prompted for server Administrator account password
To see the configured (Scheduled Tasks) in command line mode with a command:
Schtasks.exe
8 / 10
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
http://www.pc-freak.net/blog
crontab -u root -l
If you happen to need to delete just created task or any other task from command line (Assuming that you
9 / 10
Walking in Light with Christ - Faith, Computing, Diary
Articles & tips and tricks on GNU/Linux, FreeBSD, Windows,
mobile phone articles, religious related texts
http://www.pc-freak.net/blog
SUCCESS: The scheduled task "Tomcat Restart Task" was successfully deleted.
Task completed, Tomcat will auto-restart on Windows host at your scheduled time. Feedback is
mostly welcome :)
Enjoy
10 / 10
Powered by TCPDF (www.tcpdf.org)