Shell script to replace the tomcat cluster war package

Source: Internet
Author: User

Shell script to replace the tomcat cluster war package

Run the command to log on to the server without ssh.

The configuration file does not change much to overwrite the previous configuration.

Profile configuration file

Bak =/home/wsm/bak
Webapps =/home/wsm/webapps/WSMMeasure
Arry = 192.168.68.29 192.168.10.147
Newwar = 1.war
Deplypath =/home/wsm/deploy

Scp. sh copy the war and script to the remote service.

Scp. sh

#! /Bin/bash # copy war | deploy. sh | profile # scp 1.war deploy. sh profile root@192.168.68.29:/home/wsm scpdep () {echo 'start Scp... 'scp $1 deploy. sh backup. sh profile $2 @ $3: $4 echo 'end Scp... '} # arry = "192.168.68.29 192.168.10.147" host = 'awk-F' = ''{if ($1 =" arry ") print $2} 'profile 'newwar = 'awk-F' = ''{if ($1 =" newwar ") print $2} 'profile 'for I in $ hostdo echo 'scp root @' $ iscpdep $ newwar root $ I/home/wsmecho 'scp root @... stop 'done

Backup script backup. sh

 

#! /Bin/bash # dire = "/home/wsm/bak" # Back up webbench function backupWeb () {echo 'backup Start .... ''\ cp-R/home/wsm/webapps/WSMMeasure $ dire 'CD $ direrm-rf $ dirdatemv $ dire/WSMMeasure $ dirdateecho 'backup end'} dirdate = 'date + % Y % m % d 'echo '$ dirdate' dire = 'awk-F' = ''{if ($1 =" bak ") print $2} 'profile 'if [-d "$ dire"]; then echo "bak folder" else mkdir-p $ dire fibackupWeb

Installation script deploy. sh

#! /Bin/bash # dire = "/home/wsm/bak" # Back up webapps # cp war to/home/wsm/webapps/WSMMeasurefunction cpWarApps () {echo 'cpwarapps Start... 'rm-rf/home/wsm/webapps/WSMMeasure/* '\ cp/home/wsm/$1/home/wsm/webapps/WSMMeasure 'CD/home/wsm/webapps /WSMMeasurejar-xvf *. warecho 'cpwarapps End... '} # copy the configuration file function RepConf () {#/home/wsm/webapps/WSMMeasure/WEB-INF/classes # $ dire/$ dirdate/WEB-INF/classesdirdate = 'date + % Y % m % d 'echo 'RepConf Start. .. ''\ cp-R $ dire/$ dirdate/WEB-INF/classes/spring/home/wsm/webapps/WSMMeasure/WEB-INF/classes'' \ cp-R $ dire/$ dirdate /WEB-INF/classes/hbase/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp-R $ dire/$ dirdate/WEB-INF/classes/dubbo/home/wsm/ webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/xmpp. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/quertz. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/file. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/const. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/jdbc. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes 'echo 'RepConf End... '<span style = "white-space: pre"> </span>} # Stop tomcatfunction killTomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk '{print $2}' | xargs kill-9 echo "killd tomcat"} function startTomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk '{print $2}' | xargs kill-9cd/home/wsm/ bin. /startup. sh echo "start tomcat end"} dire = 'awk-F' = ''{if ($1 =" bak ") print $2} 'profile 'newwar = 'awk-F' = ''{if ($1 =" newwar ") print $2} 'profile 'backupWebcpWarApps $ newwarRepConfkillTomcatstartTomcat # LocatIP = ifconfig | grep 'inet addr:' | grep-V' 127. 0.0.1 '| cut-d: -f2 | awk '{print $1}' # STATUS_CODE = 'curl-o/dev/null-s-m 13 -- connect-timeout 20-w % {http_code} $ LocatIP: 8080/WSMMeasure/str/report/performancereport'

Remotely execute rangerun. sh

Execute the script scp to the target server through ssh

#! /Bin/bash

# Log on to the remote execution script through ssh # ssh root @ host cd/home/wsm. /deploy. sh # ssh root@192.168.68.29 "cd/home/wsm & ls" rangback () {ssh root @ $1 "cd/home/wsm &&. /backup. sh "} rangdeploy () {ssh root @ $1" cd/home/wsm &&. /deploy. sh "} # arry =" 192.168.68.29 192.168.10.147 "host = 'awk-F' ='' {if ($1 = "arry ") print $2} 'profile 'for I in $ hostdo echo 'ssh root @-Backup start... '$ irangback $ iecho' ssh root @-end of backup... stop '$ iecho' to start installation... '$ irangdeploy $ iecho' End installation... '$ idone
</Pre> <pre code_snippet_id = "507753" snippet_file_name = "blog_20141104_4_9361903" name = "code" class = "java"> rollback script rollback. sh
<Pre name = "code" class = "java"> #! /Bin/bash # Roll Back 1 stop tomcat 2 Delete the backup in webapp content 3bak copy to webapp 4 start tomcat # Stop tomcatfunction killTomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk '{print $2}' | xargs kill-9} function startTomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk '{print $2}' | xargs kill-9cd/home/wsm/ bin. /startup. sh} function rollback () {echo 'start rollback .... '#' \ cp-R/home/wsm/webapps/WSMMeasure $ dire 'rm-rf/home/wsm/webapps/WSMMeasure/* '\ cp-R/home/wsm /bak/$ dirdate/*/home/wsm/webapps/WSMMeasure/'} dirdate = 'date + % Y % m % d' killTomcatrollbackstartTomcat

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.