Skip to content

Instantly share code, notes, and snippets.

@mughilanand
Last active December 17, 2015 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mughilanand/5554615 to your computer and use it in GitHub Desktop.
Save mughilanand/5554615 to your computer and use it in GitHub Desktop.
Tomcat Startup and Shutdown script for Three Instances.
#!/bin/bash
# Tomcat Startup and Shutdown Script For Individual Instances
# Created By Mughil Anand Nainar
export JAVA_HOME="/usr/local/java/java"
export CATALINA_HOME="/usr/local/tomcat/instance1"
export JAVA_OPTS="-server -Dapp.log.environment=test -Xmx1024M -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+PrintGCDateStamps -Xloggc:/var/log/tomcat/gc.log -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Dsun.lang.ClassLoader.allowArraySyntax=true -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
start() {
export CATALINA_BASE="/usr/local/tomcat/$1"
export JAVA_OPTS="${JAVA_OPTS} -Dlog.home=/usr/local/tomcat/$1/logs"
echo "Starting Tomcat $1 "
$CATALINA_HOME/bin/catalina.sh start
}
stop() {
export CATALINA_BASE="/usr/local/tomcat/$1"
export JAVA_OPTS="${JAVA_OPTS} -Dlog.home=/usr/local/tomcat/$1/logs"
echo "Stopping Instance $1"
exec $CATALINA_HOME/bin/catalina.sh stop
echo -n " Wait for 5 Seconds "
pid=$(tomcat_pid $1)
if [ -n "$pid" ];
then
kill -9 `ps aux | grep "[t]omcat/$1" | awk '{print $2}'`
fi
echo -n " Successfully Stopped Tomcat $1 "
echo ""
}
restart() {
stop $1 && start $1
}
tomcat_pid() {
echo `ps aux | grep "[t]omcat/$1" | awk '{print $2}'`
}
version() {
exec $CATALINA_HOME/bin/version.sh
}
instance1() {
if [ " $2 " == " start " ];
then
start $1
elif [ " $2 " == " stop " ];
then
stop $1
else
restart $1
fi
}
instance2() {
if [ " $2 " == " start " ];
then
start $1
elif [ " $2 " == " stop " ];
then
stop $1
else
restart $1
fi
}
instance2() {
if [ " $2 " == " start " ];
then
start $1
elif [ " $2 " == " stop " ];
then
stop $1
else
restart $1
}
case "$1" in
instance1)
instance1 $1 $2
;;
instance2)
instance2 $1 $2
;;
instance3)
instance3 $1 $2
;;
version)
version
;;
*)
echo " Unconfigured Instance -- USAGE: tomcat_instance.sh {instance1|instance2|instance3} {start|stop|restart} "
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment