Last active
August 29, 2015 14:01
-
-
Save hardyoyo/5d4eda3b574edec005cb to your computer and use it in GitHub Desktop.
tomcat6 start script for a binary download of Apache Tomcat 6, on RHEL/CentOS (runs as the user dspace, if you're not using dspace, change to suit)
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 | |
# Tomcat6: Start/Stop Tomcat 6 | |
# chkconfig: - 90 10 | |
# script borrowed from http://seriousbirder.com/blogs/how-to-install-tomcat-7-on-rhel-6/ | |
# with extra oomph from http://blog.botha.us/sarel/?p=101 | |
### BEGIN INIT INFO | |
# Provides: tomcat6 | |
# Required-Start: $network $syslog | |
# Required-Stop: $network $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Description: Tomcat 6 service | |
# Short-Description: start and stop tomcat6 | |
### END INIT INFO | |
# Source function library | |
. /etc/init.d/functions | |
#. /etc/sysconfig/network | |
export TOMCAT_USER=dspace | |
export JAVA_HOME=/etc/alternatives/java_sdk_1.7.0 | |
export CATALINA_HOME=/usr/local/tomcat6 | |
export CATALINA_BASE=$CATALINA_HOME | |
export LOCKFILE=/var/lock/subsys/tomcat6 | |
export CATALINA_PID="$CATALINA_HOME/work/catalina.pid" | |
# Number of seconds to wait after nicely requesting stop | |
export SHUTDOWN_WAIT=10 | |
RETVAL=0 | |
start(){ | |
echo "Starting Tomcat6: " | |
su $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh" | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && touch $LOCKFILE | |
return $RETVAL | |
} | |
stop(){ | |
pid=`cat $CATALINA_PID 2>/dev/null` | |
if [ -n "$pid" ] | |
then | |
echo -n "Stopping Tomcat" | |
/bin/su -p -s /bin/sh $TOMCAT_USER $CATALINA_HOME/bin/shutdown.sh | |
RETVAL=$? | |
let kwait=$SHUTDOWN_WAIT | |
count=0; | |
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ] | |
do | |
echo -n "."; | |
sleep 1 | |
let count=$count+1; | |
done | |
echo "" | |
if [ $count -gt $kwait ]; then | |
echo "process is still running after $SHUTDOWN_WAIT seconds, killing process" | |
kill $pid | |
sleep 3 | |
# if it's still running use kill -9 | |
if [ `ps -p $pid | grep -c $pid` -gt '0' ]; then | |
echo "process is still running, using kill -9" | |
kill -9 $pid | |
sleep 3 | |
fi | |
fi | |
if [ `ps -p $pid | grep -c $pid` -gt '0' ]; then | |
echo "process is still running, I give up" | |
else | |
# success, delete PID file and LOCKFILE | |
echo "process is stopped, removing LOCKFILE and PID..." | |
if [ -e $CATALINA_PID ] | |
then | |
rm $CATALINA_PID | |
fi | |
if [ -e $LOCKFILE ] | |
then | |
rm $LOCKFILE | |
fi | |
fi | |
else | |
echo "Tomcat6 is not running" | |
fi | |
return 0 | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
status) | |
status -p $CATALINA_PID | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|status}" | |
exit 1 | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment