莫大人

linux自动更新代码,自动备份数据库,打包应用发布

切换root用户

sudo su -

1.安装svn,mysql

yum install subversion

yum install mysql

2.安装 maven

下载:百度云盘地址为

 http://pan.baidu.com/s/1nuKQGjv

解压

tar -zxvf apache-maven-3.0.5-bin.tar.gz -C /apps/svr/maven/apache-maven-3.0.5

3.配置maven环境变量

export MAVEN_HOME=/apps/svr/maven/apache-maven-3.0.5
export PATH=${MAVEN_HOME}/bin:${PATH}

 

4.checkout 

svn checkout svn://url

 

5.启动脚本 publish.sh

 

#!/bin/sh
currentDay=`date +%Y%m%d`
currentTime=`date +%Y%m%d%H%M%S`

tomcat1=/apps/tomcat/tomcat1/apache-tomcat-7.0.69
tomcat2=/apps/tomcat/tomcat2/apache-tomcat-7.0.69
confDir=/apps/conf
svnDir=/apps/svn

echo ">>>>>>>>>>>>>>>>>>>>>>>>备份数据库" 
sh /apps/sh/backup.sh
echo ">>>>>>>>>>>>>>>>>>>>>>>>更新代码" 
cd $svnDir 
svn up
echo ">>>>>>>>>>>>>>>>>>>>>>>>编译打包"
mvn -U clean install -DskipTests -X
sleep 120s 
echo ">>>>>>>>>>>>>>>>>>>>>>>>备份版本"
mkdir -p /apps/war/$currentDay
cp $svnDir/efc.eac.war/target/efc.eac.war.war /apps/war/$currentDay/"efc.eac.war_$currentTime".war
echo ">>>>>>>>>>>>>>>>>>>>>>>>停止tomcat1" 
#sh $tomcat1/bin/shutdown.sh
kill -9 `cat /apps/conf/pid/tomcat1.pid`
sleep 120s 
echo ">>>>>>>>>>>>>>>>>>>>>>>>删除tomcat1下的文件" 
rm -rf $tomcat1/webapps/efc.eac.war
echo ">>>>>>>>>>>>>>>>>>>>>>>>发布tomcat1"
unzip $svnDir/efc.eac.war/target/efc.eac.war.war -d $tomcat1/webapps/efc.eac.war
sleep 20s
echo ">>>>>>>>>>>>>>>>>>>>>>>>复制tomcat1环境配置文件"
cp $confDir/tomcat1/system.properties $tomcat1/webapps/efc.eac.war/WEB-INF/classes/
echo ">>>>>>>>>>>>>>>>>>>>>>>>启动 tomcat1" 
sh $tomcat1/bin/startup.sh
sleep 180
echo ">>>>>>>>>>>>>>>>>>>>>>>>停止tomcat2" 
#sh $tomcat2/bin/shutdown.sh
kill -9 `cat /apps/conf/pid/tomcat2.pid`

sleep 120s
echo ">>>>>>>>>>>>>>>>>>>>>>>>删除tomcat2下的文件" 
rm -rf $tomcat2/webapps/efc.eac.war
echo ">>>>>>>>>>>>>>>>>>>>>>>>发布tomcat2"
unzip $svnDir/efc.eac.war/target/efc.eac.war.war -d $tomcat2/webapps/efc.eac.war
sleep 20s 
echo ">>>>>>>>>>>>>>>>>>>>>>>>复制tomcat2环境配置文件"
cp $confDir/tomcat2/system.properties $tomcat2/webapps/efc.eac.war/WEB-INF/classes/
echo ">>>>>>>>>>>>>>>>>>>>>>>>启动 tomcat2" 
sh $tomcat2/bin/startup.sh

 

 

6.数据库备份脚本 backup.sh

#! /bin/bash
#备份地址
backupdir=/apps/war
curr_date=`date +%Y%m%d`
time=`date +%Y%m%d%H%M%S`
db_ip=10.24.66.155
db_name=eac_sit
db_user=eac_sit
db_pass=Eac_sit#1221
mkdir -p $backupdir/$curr_date
#备份数据库
mysqldump -u$db_name -h$db_ip -p$db_pass --single-transaction  $db_name | gzip > $backupdir/$curr_date/$db_name$time.sql.gz
#清除五天前的备份
find $backupdir/$curr_date -name $db_name"*.sql.gz" -type f -mtime +5 -exec rm -rf {} \;>/dev/null 2>&1

  

7.查看启动日志

more /var/spool/mail/apps

 

8.设置定时任务,定时发布版本

crontab -e

 

每天10,16点自动执行

0 10,16 * * * sh /apps/sh/publish.sh

 

posted on 2017-01-05 08:46  莫大人  阅读(194)  评论(0编辑  收藏  举报

导航