aspose file tools*
The moose likes Tomcat and the fly likes graceful windows command line shutdown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "graceful windows command line shutdown" Watch "graceful windows command line shutdown" New topic
Author

graceful windows command line shutdown

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20582
    ∞

I can hit ctrl-c with the best of them. When I do this, I see a bunch of messages about things gone bad and then a window pops up wanting to know if I want to notify microsoft about my system problems.

I would like to make a batch file that I could put in my project called bounce.bat. It would tell tomcat to gracefully shutdown and block until tomcat was all done. Then it would call "ant deploy" - where I would pretty much delete everything in the tomcat webapps directory, then drop a fresh war file. Then it would start tomcat back up.

Is this too much to ask?


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Here's one that I use.
It does it the opposit way from what you just described (the ant script calls the shell/batch script)
Like yourself, I feel more comfortable with a complete shutdown of Tomcat.
Since I'm doing that, I never needed to install the ANT tasks for deploying.

This script probably does more than what you want so you'll have to weed out what's junk to you:

It:
  • Deletes the current copy of the application
  • Pulls the entire project from CVS to the scratch directory
  • Does some string replacement (version numbers, connection strings, etc)
  • Compiles all the Java classes (by calling nested build scripts)
  • Jars up all the class files and deletes the source (this removes the temptation to make a fix on the build server instead of doing in the developer's environment and checking it into CVS)
  • Packs everything into a war file.
  • Calls a shell script that restarts Tocmat

  • CD tomcat/bin
    ./shutdown.sh
    ./startup.sh
  • Sleeps for a while, giving tomcat a chance to wake up and deploy the new war file.
  • Moves some non-shipping files into directories within the app.
  • Says "done"


  • sample.build.xml
    I'm sure an ANT guru could show me better ways to do some of this stuff but it does what I need.


    At least one of the tags was a problem for the forum software and it would have been too time consuming to figure out which so I provided a link to it instead.


    For a winders box you just need to change the ./startup.sh to startup etc.
    Or... If you're running Tomcat as a service, you can use:
    net stop TOMCAT_SERVICE_NAME
    net start TOMCAT_SERVICE_NAME
    [ January 13, 2006: Message edited by: Ben Souther ]

    Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
    paul wheaton
    Trailboss

    Joined: Dec 14, 1998
    Posts: 20582
        ∞

    do you have a shutdown and startup for windows?
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410




    Or, if you're running Tomcat as a service.


    You can get the service name by looking in the properties window from the services screen. I just looked on one of our windows boxes and it's "Tomcat5"
    [ January 13, 2006: Message edited by: Ben Souther ]
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    Graceful would be a stretch but it is thorough.
    William Brogden
    Author and all-around good cowpoke
    Rancher

    Joined: Mar 22, 2000
    Posts: 12789
        
        5
    I have a question about running shutdown.bat immediately followed by startup.bat
    Typically my Tomcat takes quite a while to go through the shutdown routine so I always wait till it vanishes from the processes list. Is it safe to start a new instance with startup.bat while the old one is still shutting down?
    Bill
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    I do it all the time with the shell scripts in Linix.
    The new one runs under a different process.
    I can't say for sure with Windows.

    If it is a problem, you could always run the shutdown script, then build the project before calling startup.
    Or, use Ant's sleep task to insure that there is some time between the two.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: graceful windows command line shutdown