当前位置:首页 > 开发 > 系统架构 > shell > 正文

【自动构建系列】自动部署环境的shell脚本

发表于: 2014-02-25   作者:cywhoyi   来源:转载   浏览次数:
摘要: #!/bin/bashDAY=`date +%Y-%m-%d-%H:%M:%S`#the path for deleting the log and tmpAPP_MAIN_PATH=/data/yousystem/jboss-5.1.0.GA/server/default#the key word for searching the process idPID_MSG=yousystem/#ms

#!/bin/bash

DAY=`date +%Y-%m-%d-%H:%M:%S`

#the path for deleting the log and tmp
APP_MAIN_PATH=/data/yousystem/jboss-5.1.0.GA/server/default

#the key word for searching the process id
PID_MSG=yousystem/

#msg of the file which is running now,backup it.
APP_FILE_NAME1=yousystem.war
APP_FILE_PATH1=/data/yousystem/jboss-5.1.0.GA/server/default/deploy

#msg of the start file which is used to start the system
APP_START_FILE=app-run.sh
APP_START_PATH=/data/yousystem

#msg of the update file
BUILD_FILE_NAME1=yousystem.war
BUILD_FILE_PATH=/data/backup/autobuild/build_files_backup

#msg of the old files for backup
OLD_FILE_PATH=/data/backup/autobuild/old_files_backup

#path of the shell script log
SHELL_LOG_PATH=/data/backup/autobuild

echo '=============================adp==================================='>>$SHELL_LOG_PATH/log_build.log
mkdir -p /data/backup
mkdir -p /data/backup/autobuild
mkdir -p /data/backup/autobuild/auto-build-scripts
mkdir -p /data/backup/autobuild/build_files_backup
mkdir -p /data/backup/autobuild/old_files_backup

#关闭正在运行的系统
time_now_1=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_1 'Begin to kill the progress.....'>>$SHELL_LOG_PATH/log_build.log
pid=`ps -ef|grep $PID_MSG|grep -v grep|awk '{print $2}'`
if [ -n "$pid" ]
then
echo 'The pid: ' $pid ' will be killed....'>>$SHELL_LOG_PATH/log_build.log
kill -9 $pid
fi
rm -rf $APP_MAIN_PATH/log/ $APP_MAIN_PATH/tmp/ $APP_MAIN_PATH/work/
time_now_2=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_2 'End to kill the progress.....'>>$SHELL_LOG_PATH/log_build.log

#备份现有的环境,具体的备份路径和范围由个人决定
echo '*******************************************************'>>$SHELL_LOG_PATH/log_build.log
time_now_3=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_3 'Begin to backup the files: '$APP_FILE_NAME1>>$SHELL_LOG_PATH/log_build.log
cp -r $APP_FILE_PATH1/$APP_FILE_NAME1 $OLD_FILE_PATH/$APP_FILE_NAME1-$DAY
time_now_4=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_4 'End to backup the files.....'>>$SHELL_LOG_PATH/log_build.log

#备份完之后先删除掉现有的环境,备份哪些就删除哪些,主要是怕覆盖的时候有文件错误
echo '*******************************************************'>>$SHELL_LOG_PATH/log_build.log
time_now_5=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_5 'Begin to delete the files: ' $APP_FILE_NAME1>>$SHELL_LOG_PATH/log_build.log
rm -rf $APP_FILE_PATH1/$APP_FILE_NAME1
time_now_6=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_6 'End to delete the files....'>>$SHELL_LOG_PATH/log_build.log

#把最新build的文件拷贝到需要解压的目录
echo '*******************************************************'>>$SHELL_LOG_PATH/log_build.log
time_now_7=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_7 'Begin to copy the build files: ' $BUILD_FILE_NAME1>>$SHELL_LOG_PATH/log_build.log
cp -r $BUILD_FILE_PATH/$BUILD_FILE_NAME1 $APP_FILE_PATH1
time_now_8=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_8 'End to copy the build files.....'>>$SHELL_LOG_PATH/log_build.log

#删除环境上的缓存文件
echo '*******************************************************'>>$SHELL_LOG_PATH/log_build.log
time_now_9=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_9 'Begin to backup the build files: ' $BUILD_FILE_NAME1>>$SHELL_LOG_PATH/log_build.log
mv -f $BUILD_FILE_PATH/$BUILD_FILE_NAME1 $BUILD_FILE_PATH/$BUILD_FILE_NAME1-$DAY
time_now_10=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_10 'End to backup the build files.....'>>$SHELL_LOG_PATH/log_build.log


#解压新build的文件(视个人项目而定,一般war包不需要解压,但是这里我们需要去修改war包中的配置文件)
echo '*******************************************************'>>$SHELL_LOG_PATH/log_build.log
time_now_11=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_11 'Begin to uncompress the files: ' $BUILD_FILE_NAME1>>$SHELL_LOG_PATH/log_build.log
cd $APP_FILE_PATH1
mkdir unwar
echo 'mkdir success'>>$SHELL_LOG_PATH/log_build.log
cp -r $APP_FILE_NAME1 unwar/
echo 'copy file success'>>$SHELL_LOG_PATH/log_build.log
cd unwar/
jar -xf $APP_FILE_NAME1
echo 'uncompress file success'>>$SHELL_LOG_PATH/log_build.log
rm -rf $APP_FILE_NAME1
echo 'delete the copy file success'>>$SHELL_LOG_PATH/log_build.log
cd $APP_FILE_PATH1
rm -rf $APP_FILE_NAME1
echo 'delete the update file success'>>$SHELL_LOG_PATH/log_build.log
mv unwar $APP_FILE_NAME1
echo 'change the folder name success'>>$SHELL_LOG_PATH/log_build.log
time_now_12=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_12 'End to uncompress the files:.....'>>$SHELL_LOG_PATH/log_build.log

#重启系统
echo '*******************************************************'>>$SHELL_LOG_PATH/log_build.log
time_now_13=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_13 'Begin to restart the system....'>>$SHELL_LOG_PATH/log_build.log
echo 'Start File is: ' $APP_START_PATH/$APP_START_FILE>>$SHELL_LOG_PATH/log_build.log
sh $APP_START_PATH/$APP_START_FILE
time_now_14=`date +%Y-%m-%d" "%H:%M:%S`
echo $time_now_14 'End to restart the system....'>>$SHELL_LOG_PATH/log_build.log

【自动构建系列】自动部署环境的shell脚本

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
一。使用jenkins进行持续集成的一般流程: 1.第一步:上传项目。 我使用的是Intellij idea 开发的we
最近在编写自动化构建脚本,大概的思想是,将cvs中某一tag的export出来,根据编写好的ant脚本,ant
最近在编写自动化构建脚本,大概的思想是,将cvs中某一tag的export出来,根据编写好的ant脚本,ant
本文转自http://blog.csdn.net/ybygjy/article/details/6135915 Java单元测试,测试环境、自动构建
原文: SQL Server自动化运维系列——监控性能指标脚本(Power Shell) 需求描述 一般在生产环境中,
需求描述 一般在生产环境中,有时候需要自动的检测指标值状态,如果发生异常,需要提前预警的,比如
《SVN与TortoiseSVN实战系列》已写完,今天新开一个《Jenkins自动化构建系列》,上周听了Bob Jiang
1、简单自动生成文本脚本: cat > word1.txt 创建文本时 会等待输入,如果想不等待输入,直接生
标题很大,想说的很多,不知道从那开始~~直接步入正题吧   个人也是由于公司的人员的现状和项目的
任发科:构建大型软件企业的自动化部署 如何构建大型软件企业的自动化部署?现如今部署面临着很多矛
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号