-
-
Save mnadel/8102958 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# tomcat7 This shell script takes care of starting and stopping Tomcat | |
# | |
# chkconfig: - 80 20 | |
# | |
### BEGIN INIT INFO | |
# Provides: tomcat | |
# Required-Start: $network $syslog | |
# Required-Stop: $network $syslog | |
# Default-Start: | |
# Default-Stop: | |
# Description: Apache Tomcat | |
# Short-Description: Start and stop Apache Tomcat | |
### END INIT INFO | |
. /etc/rc.d/init.d/functions | |
. /etc/default/tomcat | |
export JAVA_HOME=${JAVA_HOME:=/usr/java/default} | |
export PATH=$JAVA_HOME/bin:$PATH | |
export TOMCAT_HOME=${TOMCAT_HOME:=/opt/tomcat} | |
export TOMCAT_LOGS=${TOMCAT_LOGS:=/var/log/tomcat} | |
export CATALINA_PID=${CATALINA_PID:=$TOMCAT_HOME/tomcat.pid} | |
export TOMCAT_USER=${TOMCAT_USER:=tomcat} | |
export JAVA_OPTS=${JAVA_OPTS:="-Dfile.encoding=UTF-8 \ | |
-Dcatalina.logbase=$TOMCAT_LOGS \ | |
-Dnet.sf.ehcache.skipUpdateCheck=true \ | |
-XX:+DoEscapeAnalysis \ | |
-XX:+UseConcMarkSweepGC \ | |
-XX:+CMSClassUnloadingEnabled \ | |
-XX:+UseParNewGC \ | |
-XX:MaxPermSize=128m \ | |
-Xms1g \ | |
-Xmx1g"} | |
SHUTDOWN_WAIT=20 | |
usage() { | |
echo "$(basename $0) [start|stop|restart|status]" | |
} | |
tomcat_pid() { | |
if [[ -z $CATALINA_PID && -e $CATALINA_PID ]]; then | |
cat $CATALINA_PID | |
else | |
echo $(ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }') | |
fi | |
} | |
start() { | |
pid=$(tomcat_pid) | |
if [ -n "$pid" ]; then | |
echo "Tomcat is already running (pid: $pid)" | |
else | |
echo "Starting tomcat" | |
ulimit -n 100000 | |
umask 007 | |
/bin/su -p $TOMCAT_USER -c $TOMCAT_HOME/bin/startup.sh | |
fi | |
return 0 | |
} | |
stop() { | |
pid=$(tomcat_pid) | |
if [ -n "$pid" ]; then | |
echo "Stoping Tomcat" | |
/bin/su -p $TOMCAT_USER -c $TOMCAT_HOME/bin/shutdown.sh | |
let kwait=$SHUTDOWN_WAIT | |
count=0; | |
until [ $(ps -p $pid | grep -c $pid) = 0 ] || [ $count -gt $kwait ]; do | |
echo -n -e "Waiting for processes to exit\n" | |
sleep 1 | |
let count=$count+1 | |
done | |
if [ $count -gt $kwait ]; then | |
echo -n -e "killing pid $pid which didn't stop after $SHUTDOWN_WAIT seconds\n" | |
kill -9 $pid | |
fi | |
else | |
echo "Tomcat is not running" | |
fi | |
return 0 | |
} | |
case $1 in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
status) | |
pid=$(tomcat_pid) | |
if [ -n "$pid" ]; then | |
echo "Tomcat is running with pid: $pid" | |
else | |
echo "Tomcat is not running" | |
fi | |
;; | |
*) | |
usage | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment