Blog > Resolving Tomcat's Hangups
The ritual of restarting Tomcat whenever a new jar is added or an upgrade results in their names changing is, I am sure, familiar to all of us developing Java-based sites.
Over time we've developed a set of handy aliases to handle the regular ups and downs and keeping an eye on Catalina.out, tomcat's log file of choice. Recently however, I've been having to make more frequent search-and-destroy excursions to resolve hanging processes. After a couple dozen repetitions and mutterings about wishing for a one-liner, I decided to navigate the murky waters of command-line scripting.
The result of a bit of munging and googling is a fantastic one-liner (or if you configure it as an alias, one-worder):
ps -auxww|grep java|grep tomcat|grep -v grep|awk "{system("sudo kill "$2 " > /dev/null")}
And because they've made my work so much more convenient, here's my full set of aliases, ready to be dropped into your .profile (all you need to do is define your TOMCAT_HOME):
alias tomstart='$TOMCAT_HOME/bin/startup.sh'
alias tomstop='$TOMCAT_HOME/bin/shutdown.sh'
alias tomlog='tail -f $TOMCAT_HOME/logs/catalina.out'
alias tomgrep='ps -auxww|grep tomcat'
alias tomkill='ps -auxww|grep java|grep tomcat|grep -v grep|awk "{system("sudo kill "$2 " > /dev/null")}"'
Over time we've developed a set of handy aliases to handle the regular ups and downs and keeping an eye on Catalina.out, tomcat's log file of choice. Recently however, I've been having to make more frequent search-and-destroy excursions to resolve hanging processes. After a couple dozen repetitions and mutterings about wishing for a one-liner, I decided to navigate the murky waters of command-line scripting.
The result of a bit of munging and googling is a fantastic one-liner (or if you configure it as an alias, one-worder):
ps -auxww|grep java|grep tomcat|grep -v grep|awk "{system("sudo kill "$2 " > /dev/null")}
And because they've made my work so much more convenient, here's my full set of aliases, ready to be dropped into your .profile (all you need to do is define your TOMCAT_HOME):
alias tomstart='$TOMCAT_HOME/bin/startup.sh'
alias tomstop='$TOMCAT_HOME/bin/shutdown.sh'
alias tomlog='tail -f $TOMCAT_HOME/logs/catalina.out'
alias tomgrep='ps -auxww|grep tomcat'
alias tomkill='ps -auxww|grep java|grep tomcat|grep -v grep|awk "{system("sudo kill "$2 " > /dev/null")}"'
Posted by Martin Kuplens-Ewart on Friday, November 10, 2006 at 12:00 PM in Java with tags tomcat, restarting, kill, grep, command-line • Permalink • 0 comments
Comments
Sorry! No comments found. Please check back soon...Post a New Comment
Please note that comments are moderated to prevent abuse of the comment system and will only appear after they have been approved by the author of this post. Use the "View Source" mode to edit HTML directly if you're into that kind of thing. We might not approve posts that are offensive or really off-topic, and we will definitely delete spam (and place nasty, nasty curses on the spammers).

