Skip to content

Instantly share code, notes, and snippets.

@ldez
Last active January 1, 2016 17:38
Show Gist options
  • Save ldez/8178045 to your computer and use it in GitHub Desktop.
Save ldez/8178045 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# chkconfig: 2345 96 30
# description: start and stop Tomcat server
# Script version
SCRIPT_VERSION=1.0
JAVA_HOME=/usr/local/jdk1.7.0_45
# Tomcat main folder
CATALINA_HOME=/opt/tomcat
# Tomcat instance folder
CATALINA_BASE=/apps/user/tomcat
CMD_TCPID="ps aux | grep '\\-Dcatalina.base=$CATALINA_BASE' | grep 'org.apache.catalina.startup.Bootstrap' | grep -v grep | awk '{print \$2}'"
TOMCAT_START=${CATALINA_HOME}/bin/startup.sh
TOMCAT_STOP=${CATALINA_HOME}/bin/shutdown.sh
JAVA_OPTS="-server -Xmx2048m"
export CATALINA_HOME CATALINA_BASE JAVA_HOME JAVA_OPTS
start()
{
TCPID=`eval ${CMD_TCPID}`
if [ -n "$TCPID" ]; then
echo "Tomcat server is already running with pid=$TCPID."
elif [ -x ${TOMCAT_START} ]; then
echo "Starting tomcat server..."
${TOMCAT_START} #&
else
echo "Cannot start tomcat server."
fi
}
stop()
{
TCPID=`eval ${CMD_TCPID}`
if [ -z "$TCPID" ]; then
echo "Tomcat server is not running."
elif [ -x ${TOMCAT_STOP} ]; then
echo "Stopping tomcat server..."
${TOMCAT_STOP} #&
else
echo "Cannot stop tomcat server."
fi
}
restart()
{
stop
sleep 10
start
}
status()
{
TCPID=`eval ${CMD_TCPID}`
if [ -n "$TCPID" ]; then
echo "Tomcat server is running with pid=$TCPID."
else
echo "Tomcat server is not running."
fi
}
case "$1" in
"start")
start
;;
"stop")
stop
;;
"restart")
restart
;;
"status")
status
;;
*)
echo Tomcat control script ${SCRIPT_VERSION}
echo "Usage [start|stop|restart|status]"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment