Last active
December 23, 2015 18:59
-
-
Save lifuzu/6679724 to your computer and use it in GitHub Desktop.
put it into /etc/init.d/tomcat
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 | |
### BEGIN INIT INFO | |
# Provides: tomcat | |
# Required-Start: $network | |
# Required-Stop: $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start/Stop Tomcat server | |
### END INIT INFO | |
# Command: | |
# sudo chmod 755 /etc/init.d/tomcat | |
# sudo update-rc.d tomcat defaults | |
# then you can start|stop|restart with the following commands: | |
# sudo service tomcat <stop|start|restart> | |
export PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
export JAVA_HOME=/usr/lib/jvm/java-7-sun | |
export PATH=${JAVA_HOME}/bin:$PATH | |
export CATALINA_HOME=/usr/local/tomcat | |
export PATH=${CATALINA_HOME}/bin:$PATH | |
#export JAVA_OPTS="-Dfile.encoding=UTF-8 \ | |
# -Dcatalina.logbase=/var/log/tomcat7 \ | |
# -Dnet.sf.ehcache.skipUpdateCheck=true \ | |
# -XX:+DoEscapeAnalysis \ | |
# -XX:+UseConcMarkSweepGC \ | |
# -XX:+CMSClassUnloadingEnabled \ | |
# -XX:+UseParNewGC \ | |
# -XX:MaxPermSize=128m \ | |
# -Xms512m -Xmx512m" | |
SHUTDOWN_WAIT=20 | |
tomcat_pid() { | |
echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'` | |
} | |
start() { | |
pid=$(tomcat_pid) | |
if [ -n "$pid" ] | |
then | |
echo "Tomcat is already running (pid: $pid)" | |
else | |
# Start tomcat | |
echo "Starting tomcat" | |
ulimit -n 100000 | |
umask 007 | |
#/bin/su -p -s /bin/sh tomcat $CATALINA_HOME/bin/startup.sh | |
sh ${CATALINA_HOME}/bin/startup.sh | |
fi | |
return 0 | |
} | |
stop() { | |
pid=$(tomcat_pid) | |
if [ -n "$pid" ] | |
then | |
echo "Stoping Tomcat" | |
#/bin/su -p -s /bin/sh tomcat $CATALINA_HOME/bin/shutdown.sh | |
sh ${CATALINA_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 "\nwaiting for processes to exit"; | |
sleep 1 | |
let count=$count+1; | |
done | |
if [ $count -gt $kwait ]; then | |
echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds" | |
kill -9 $pid | |
fi | |
else | |
echo "Tomcat is not running" | |
fi | |
return 0 | |
} | |
status() { | |
pid=$(tomcat_pid) | |
if [ -n "$pid" ] | |
then | |
echo "Tomcat is running with pid: $pid" | |
else | |
echo "Tomcat is not running" | |
fi | |
} | |
case $1 in | |
start|stop) $1;; | |
restart) stop; start;; | |
status) status;; | |
*) echo "Run as $0 <start|stop|restart|status>"; exit 1;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment