Shell scripts to manage multiple Tomcat instances

Source: Internet
Author: User

In order to simplify the deployment complexity of Tomcat, the previously individually configured script was presented as a parameter that can be used for multi-tomcat instance management in a stand-alone environment.

Where the Deploy feature will rename the specified module war to be backed up by datetime and then deploy a new war

The command line format is

Tc. SH [Tomcat_location] {Status|start|stop|restart|jstat|deploy} [Module_name]

Script code

# define the absolute path of Tomcat Instancejava_home=/opt/java/jdk1.8. 0_101tc_base=/home/Tomcatbuild_folder=/home/tomcat/Buildsstatus () {Echo-N"[$ (date +%y%m%d-%h%m%s)]"PID=`PS-ef|grep${catalina_base}|grep-V'grep'|grep 'Java'|awk '{print $}'`  if[-Z ${pid}]; Then    Echo$1'is not running'  Else    Echo$1'is running at PID:'${pid}fi}start () {Echo-N"[$ (date +%y%m%d-%h%m%s)] Start:"PID=`PS-ef|grep${catalina_base}|grep-V'grep'|grep 'Java'|awk '{print $}'`  if[-Z ${pid}]; Then    Echo$1. ${catalina_base}/bin/startup.SH  Else    Echo$1'is running at PID:'${pid}fi}stop () {if[-Z $1]; ThenExit1  fi  Echo-N"[$ (date +%y%m%d-%h%m%s)] Stop:"PID=`PS-ef|grep${catalina_base}|grep-V'grep'|grep 'Java'|awk '{print $}'`  if[-Z $pid]; Then    Echo$1'is not running'  Else    Echo$1'is running at PID:'${pid}. ${catalina_base}/bin/shutdown.SH    Sleep 5  fiPID=`PS-ef|grep${catalina_base}|grep-V'grep'|grep 'Java'|awk '{print $}'`  if[-Z $pid]; Then    Echo ' Done'  Else    Echo 'still running, now killing with PID:'${pid}PS-ef|grep${catalina_base}|grep-V'grep'|grep 'Java'|awk '{print $}'|Xargs Kill-S9  fi}restart () {Stop $1  Sleep 1Start $1}deploy () {if[-Z $2]; Then    Echo$"Usage: + deploy [module_name]"Exit2  fi  [ -F ${build_folder}/$2. War] | | Exit1Stop $1  DF-hEcho "'Local Backup_filename=$2-$(Date+%y%m%d-%h%M). WarEcho-N"[$ (date +%y%m%d-%h%m%s)] Deploy:"  Echo-N"backup ${backup_filename} ..."  MV${catalina_base}/webapps/$2. War ${build_folder}/${backup_filename}Echo-N"Clean ..."  RM-RF ${catalina_base}/webapps/$2  Echo-N"copy ..."  CP-F ${build_folder}/$2. War ${catalina_base}/webapps/Echo ' Done'Start $1}jstat () {if[-Z $1]; ThenExit1  fiLocal Catalina_base=${tc_base}/$1  [ -D ${catalina_base}] | | Exit1  Echo-N"[$ (date +%y%m%d-%h%m%s)] Jstat:"PID=`PS-ef|grep${catalina_base}|grep-V'grep'|grep 'Java'|awk '{print $}'`  if[-Z $pid]; Then    Echo$1'is not running'  Else    Echo$1'is running at PID:'${pid} ${java_home}/bin/jmap-Heap ${pid}Echo "'${java_home}/bin/jstat-gcutil ${pid} + Ten  fi}if[-Z $1]; Then  Echo$"Usage: $ [tomcat_location] {status|start|stop|restart|jstat|deploy} [module_name]"Exit2ElseTarget=${1%/}fiCatalina_base=${tc_base}/$target [-D ${catalina_base}] | | Exit1 Case " $" inchstatus) $2$target;; Start) $2$target;; Stop) $2$target;; Restart) $2$target;; Jstat) $2$target;; Deploy) $2$target $3        ;; *)        Echo$"Usage: $ [tomcat_location] {status|start|stop|restart|jstat|deploy} [module_name]"Exit2Esac

Startup.sh and shutdown.sh within the corresponding Tomcat instances, only the JVM parameters and the Tomcat source path need to be configured

startup.sh

java_opts="-server-xms1024m-xmx1024m-xx:maxnewsize=512m-djava.awt.headless=true" catalina_home=/opt/tomcat/apache-tomcat-8.0.  $ . $CATALINA _home/bin/catalina. SH start

shutdown.sh

catalina_home=/opt/tomcat/apache-tomcat-8.0.  $ . $CATALINA _home/bin/catalina. SH stop

Shell scripts to manage multiple Tomcat instances

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.