写了一个生产自动部署的脚本,做个笔记!
一键部署脚本 写道
###################
# #
# author : ............... #
# date : 20161218 #
# explain: X71 shell #
###################
#Defining a parser,we use ksh
#!/bin/ksh
#The startup script, first to sleep for a second.
sleep 1
#get input first param.
#If the first parameter is empty,Access to local time format yyyymmdd for T_DATE.
#If the first parameter is not empty,T_DATE get parameter.
if [ -n $1 ]
then
T_DATE=$1
else
#format date ,AIX is date +%Y%m%d
T_DATE=$(date +%Y%m%d)
fi
#Define a log file, which is used to output the program execution log information.
mkdir -p $HOME/backup/${T_DATE}/
LOG=$HOME/backup/${T_DATE}/production_deploy.log
touch $LOG
#Create the log file
#echo 'create '$HOME/backup/${T_DATE}/production_deploy.log >> $LOG
#Handle new programs, new program from TMP is transferred to the new backup directory.
#Processing flow:
#1.First of all, create the directory '$HOME/backup/${T_DATE}/new'.
#2.Traverse under the TMP *.zip, *. The war file name.
#3.If the result is empty,Print log information 'please upload files'.
#4.If the result is not empty,Transfer the file to the '$HOME/backup/${T_DATE}/new' directory.
#5.Unpack the '$HOME/backup/${T_DATE}/new' directory *.zip file.
#
dealNewFiles(){
echo '--------------------dealNewFiles begin---------------------------' >> $LOG
mkdir -p $HOME/backup/${T_DATE}/new
echo 'mkdir -p '$HOME'/backup/'${T_DATE}'/new result is ' $? >> $LOG
##mv *.zip and *.war
cd $HOME/tmp/
zipAndWarFiles=`ls |egrep 'zip|war' |grep -v grep`
echo 'print $HOME/tmp/ *.zip & *.war :' $zipAndWarFiles >> $LOG
if [[ -n ${zipAndWarFiles[*]} ]];
then
mv ${zipAndWarFiles[@]} $HOME/backup/${T_DATE}/new
echo 'mv '${zipAndWarFiles[@]} $HOME/backup/${T_DATE}/new >> $LOG
else
echo please upload files
exit 0
fi
##unzip *.zip
cd $HOME/backup/${T_DATE}/new
echo 'cd '$HOME/backup/${T_DATE}/new >> $LOG
for loop in `ls | grep zip |grep -v grep`
do
`jar -xvf $loop`
echo 'jar -xvf '$loop' result is '$? >> $LOG
done
echo '--------------------dealNewFiles end----------------------------' >> $LOG
}
#
#Backup the old program
#According to the files in the '$HOME/backup/${T_DATE}/new/' directory names, to search for program files .
#If in the user directory that is service programs,if in the user/batch directory that is batch programs.
#Processing flow:
#1.Create '$HOME/backup/${T_DATE}/old/' directory.
#2.Traversing the '$HOME/backup/${T_DATE}/new/' files in the directory name, coexist in the array.
#3.Create a folder with the program same in the '$HOME/backup/${T_DATE}/old' directory.
#4.According to the path of the program, determine the type of program, and transferred to the name of the corresponding folder.
#
dealOldFiles(){
echo '--------------------dealOldFiles begin--------------------------' >> $LOG
mkdir -p $HOME/backup/${T_DATE}/old/
echo 'mkdir -p '$HOME/backup/${T_DATE}/old/ >> $LOG
##read new files
cd $HOME/backup/${T_DATE}/new/
echo 'ls ' $HOME/backup/${T_DATE}/new/ >> $LOG
for loop in `ls`
do
if [[ -d $loop ]] && [[ ! -d $HOME/backup/${T_DATE}/old/$loop ]]
then
mkdir -p $HOME/backup/${T_DATE}/old/$loop/
if [ -d $HOME/$loop ]
then
cp -r $HOME/$loop $HOME/backup/${T_DATE}/old/
echo 'cp -r '$HOME/$loop $HOME/backup/${T_DATE}/old/$loop >> $LOG
else
cp -r $HOME/batch/$loop $HOME/backup/${T_DATE}/old/
echo 'cp -r '$HOME/batch/$loop $HOME/backup/${T_DATE}/old/ >> $LOG
fi
fi
done
##deal ebank store folder
#if [[ $LOGIN = wcb ]]
#then
# cd /WebSphere/AppServer/profiles/Custom01/installedApps/pwcbap1Cell01/
# if [[ -d EBank_war.ear ]]
# then
# cd ./EBank_war.ear/EBank.war
# cp -r store $HOME/backup/${T_DATE}/old/
# else
# cd ./ebank_war.ear/ebank.war
# cp -r store $HOME/backup/${T_DATE}/old/
# fi
#fi
echo '--------------------dealOldFiles end----------------------------' >> $LOG
}
#
#To stop consumers module.
#Processing flow:
#1.To determine whether a folder '$HOME/backup/${T_DATE}/new/AroundServiceApp' and $LOGIN is dhtz.
#2.If consumers module, edit to the AS at the end of the folder, and kill processes.
#3.If the consumer module does not exist, the print log.
#
stopAs(){
echo '=====> stopAs begin......' >> $LOG
if [[ $LOGIN = dhtz ]] && [[ -d $HOME/backup/${T_DATE}/new/AroundServiceApp ]]
then
cd $HOME/backup/${T_DATE}/new/AroundServiceApp/
echo 'ls '$HOME/backup/${T_DATE}/new/AroundServiceApp/ >> $LOG
for loop in `ls |grep AS |grep -v sh`
do
echo 'kill -9 '$loop >> $LOG
ps -ef |grep java | grep $loop | grep -v grep | awk '{print $2}' | xargs kill -9
done
else
echo 'No consumer module.....'
fi
echo '====>stopAs end.......' >> $LOG
}
#
#Deploy new program, and start.
#Transfer the new application from the directory to corresponding program directory.
#If it is a service program, to stop the process first, then replace, finally start the new program.
#If it is batch process substitution can be directly.
#Of course don't forget to assign permissions.
#Processing flow:
#1.Traverse all the folder name in the directory.
#2.If the program under the user's path, we kill process to replace the new program, assign permissions, the last startup scripts.
# Otherwise the replacement program and assign permissions.
#
deployNewExe(){
echo '--------------------deployNewExe begin--------------------------' >> $LOG
stopAs
cd $HOME/backup/${T_DATE}/new/
echo 'ls '$HOME/backup/${T_DATE}/new/ >> $LOG
for loop in `ls`
do
if [ -d $HOME/$loop ]
then
echo 'kill -9 '$loop >> $LOG
ps -ef |grep java | grep $loop | grep -v grep | awk '{print $2}' | xargs kill -9
cd $HOME/backup/${T_DATE}/new/$loop/
cp -r * $HOME/$loop/
echo 'cp -r '$HOME/backup/${T_DATE}/new/$loop/ $HOME/$loop/ >> $LOG
cd $HOME/
chmod -R 775 $loop/
echo 'chmod -R 775 '$loop/ >> $LOG
cd $HOME/$loop/
./start.sh 1 >> /dev/null 2 >> /dev/null
echo $HOME/$loop/'./start.sh &' >>$LOG
else
cd $HOME/backup/${T_DATE}/new/$loop/
echo 'cd ' $HOME/backup/${T_DATE}/new/$loop/ >>$LOG
cp -r * $HOME/batch/$loop/
echo 'cp -r '$HOME/backup/${T_DATE}/new/$loop/ $HOME/batch/$loop/ >> $LOG
cd $HOME/batch/
chmod -R 775 $loop
echo 'chmod -R 775 '$HOME/batch/$loop/ >> $LOG
fi
done
echo '--------------------deployNewExe end----------------------------' >> $LOG
}
#The script always put in storage.
main(){
#print welcome
echo "--------------------------main----------------------------------" >> $LOG
echo "******* Welcome to production_deploy.sh ********" >> $LOG
echo >> $LOG
echo "==>" Date is $T_DATE >> $LOG
echo "==> deal new files" >> $LOG
dealNewFiles
echo "==> deal old files" >> $LOG
dealOldFiles
echo "==> deal new exe" >> $LOG
deployNewExe
}
## begin exe main
main
echo "--------------------------end-----------------------------------" >> $LOG
echo >> $LOG
echo >> $LOG
cat $LOG
exit 0
# #
# author : ............... #
# date : 20161218 #
# explain: X71 shell #
###################
#Defining a parser,we use ksh
#!/bin/ksh
#The startup script, first to sleep for a second.
sleep 1
#get input first param.
#If the first parameter is empty,Access to local time format yyyymmdd for T_DATE.
#If the first parameter is not empty,T_DATE get parameter.
if [ -n $1 ]
then
T_DATE=$1
else
#format date ,AIX is date +%Y%m%d
T_DATE=$(date +%Y%m%d)
fi
#Define a log file, which is used to output the program execution log information.
mkdir -p $HOME/backup/${T_DATE}/
LOG=$HOME/backup/${T_DATE}/production_deploy.log
touch $LOG
#Create the log file
#echo 'create '$HOME/backup/${T_DATE}/production_deploy.log >> $LOG
#Handle new programs, new program from TMP is transferred to the new backup directory.
#Processing flow:
#1.First of all, create the directory '$HOME/backup/${T_DATE}/new'.
#2.Traverse under the TMP *.zip, *. The war file name.
#3.If the result is empty,Print log information 'please upload files'.
#4.If the result is not empty,Transfer the file to the '$HOME/backup/${T_DATE}/new' directory.
#5.Unpack the '$HOME/backup/${T_DATE}/new' directory *.zip file.
#
dealNewFiles(){
echo '--------------------dealNewFiles begin---------------------------' >> $LOG
mkdir -p $HOME/backup/${T_DATE}/new
echo 'mkdir -p '$HOME'/backup/'${T_DATE}'/new result is ' $? >> $LOG
##mv *.zip and *.war
cd $HOME/tmp/
zipAndWarFiles=`ls |egrep 'zip|war' |grep -v grep`
echo 'print $HOME/tmp/ *.zip & *.war :' $zipAndWarFiles >> $LOG
if [[ -n ${zipAndWarFiles[*]} ]];
then
mv ${zipAndWarFiles[@]} $HOME/backup/${T_DATE}/new
echo 'mv '${zipAndWarFiles[@]} $HOME/backup/${T_DATE}/new >> $LOG
else
echo please upload files
exit 0
fi
##unzip *.zip
cd $HOME/backup/${T_DATE}/new
echo 'cd '$HOME/backup/${T_DATE}/new >> $LOG
for loop in `ls | grep zip |grep -v grep`
do
`jar -xvf $loop`
echo 'jar -xvf '$loop' result is '$? >> $LOG
done
echo '--------------------dealNewFiles end----------------------------' >> $LOG
}
#
#Backup the old program
#According to the files in the '$HOME/backup/${T_DATE}/new/' directory names, to search for program files .
#If in the user directory that is service programs,if in the user/batch directory that is batch programs.
#Processing flow:
#1.Create '$HOME/backup/${T_DATE}/old/' directory.
#2.Traversing the '$HOME/backup/${T_DATE}/new/' files in the directory name, coexist in the array.
#3.Create a folder with the program same in the '$HOME/backup/${T_DATE}/old' directory.
#4.According to the path of the program, determine the type of program, and transferred to the name of the corresponding folder.
#
dealOldFiles(){
echo '--------------------dealOldFiles begin--------------------------' >> $LOG
mkdir -p $HOME/backup/${T_DATE}/old/
echo 'mkdir -p '$HOME/backup/${T_DATE}/old/ >> $LOG
##read new files
cd $HOME/backup/${T_DATE}/new/
echo 'ls ' $HOME/backup/${T_DATE}/new/ >> $LOG
for loop in `ls`
do
if [[ -d $loop ]] && [[ ! -d $HOME/backup/${T_DATE}/old/$loop ]]
then
mkdir -p $HOME/backup/${T_DATE}/old/$loop/
if [ -d $HOME/$loop ]
then
cp -r $HOME/$loop $HOME/backup/${T_DATE}/old/
echo 'cp -r '$HOME/$loop $HOME/backup/${T_DATE}/old/$loop >> $LOG
else
cp -r $HOME/batch/$loop $HOME/backup/${T_DATE}/old/
echo 'cp -r '$HOME/batch/$loop $HOME/backup/${T_DATE}/old/ >> $LOG
fi
fi
done
##deal ebank store folder
#if [[ $LOGIN = wcb ]]
#then
# cd /WebSphere/AppServer/profiles/Custom01/installedApps/pwcbap1Cell01/
# if [[ -d EBank_war.ear ]]
# then
# cd ./EBank_war.ear/EBank.war
# cp -r store $HOME/backup/${T_DATE}/old/
# else
# cd ./ebank_war.ear/ebank.war
# cp -r store $HOME/backup/${T_DATE}/old/
# fi
#fi
echo '--------------------dealOldFiles end----------------------------' >> $LOG
}
#
#To stop consumers module.
#Processing flow:
#1.To determine whether a folder '$HOME/backup/${T_DATE}/new/AroundServiceApp' and $LOGIN is dhtz.
#2.If consumers module, edit to the AS at the end of the folder, and kill processes.
#3.If the consumer module does not exist, the print log.
#
stopAs(){
echo '=====> stopAs begin......' >> $LOG
if [[ $LOGIN = dhtz ]] && [[ -d $HOME/backup/${T_DATE}/new/AroundServiceApp ]]
then
cd $HOME/backup/${T_DATE}/new/AroundServiceApp/
echo 'ls '$HOME/backup/${T_DATE}/new/AroundServiceApp/ >> $LOG
for loop in `ls |grep AS |grep -v sh`
do
echo 'kill -9 '$loop >> $LOG
ps -ef |grep java | grep $loop | grep -v grep | awk '{print $2}' | xargs kill -9
done
else
echo 'No consumer module.....'
fi
echo '====>stopAs end.......' >> $LOG
}
#
#Deploy new program, and start.
#Transfer the new application from the directory to corresponding program directory.
#If it is a service program, to stop the process first, then replace, finally start the new program.
#If it is batch process substitution can be directly.
#Of course don't forget to assign permissions.
#Processing flow:
#1.Traverse all the folder name in the directory.
#2.If the program under the user's path, we kill process to replace the new program, assign permissions, the last startup scripts.
# Otherwise the replacement program and assign permissions.
#
deployNewExe(){
echo '--------------------deployNewExe begin--------------------------' >> $LOG
stopAs
cd $HOME/backup/${T_DATE}/new/
echo 'ls '$HOME/backup/${T_DATE}/new/ >> $LOG
for loop in `ls`
do
if [ -d $HOME/$loop ]
then
echo 'kill -9 '$loop >> $LOG
ps -ef |grep java | grep $loop | grep -v grep | awk '{print $2}' | xargs kill -9
cd $HOME/backup/${T_DATE}/new/$loop/
cp -r * $HOME/$loop/
echo 'cp -r '$HOME/backup/${T_DATE}/new/$loop/ $HOME/$loop/ >> $LOG
cd $HOME/
chmod -R 775 $loop/
echo 'chmod -R 775 '$loop/ >> $LOG
cd $HOME/$loop/
./start.sh 1 >> /dev/null 2 >> /dev/null
echo $HOME/$loop/'./start.sh &' >>$LOG
else
cd $HOME/backup/${T_DATE}/new/$loop/
echo 'cd ' $HOME/backup/${T_DATE}/new/$loop/ >>$LOG
cp -r * $HOME/batch/$loop/
echo 'cp -r '$HOME/backup/${T_DATE}/new/$loop/ $HOME/batch/$loop/ >> $LOG
cd $HOME/batch/
chmod -R 775 $loop
echo 'chmod -R 775 '$HOME/batch/$loop/ >> $LOG
fi
done
echo '--------------------deployNewExe end----------------------------' >> $LOG
}
#The script always put in storage.
main(){
#print welcome
echo "--------------------------main----------------------------------" >> $LOG
echo "******* Welcome to production_deploy.sh ********" >> $LOG
echo >> $LOG
echo "==>" Date is $T_DATE >> $LOG
echo "==> deal new files" >> $LOG
dealNewFiles
echo "==> deal old files" >> $LOG
dealOldFiles
echo "==> deal new exe" >> $LOG
deployNewExe
}
## begin exe main
main
echo "--------------------------end-----------------------------------" >> $LOG
echo >> $LOG
echo >> $LOG
cat $LOG
exit 0
相关推荐
7. **环境适应性**: 自动部署脚本应该具备良好的可扩展性和适应性,能够根据不同的环境(开发、测试、生产)进行参数调整。 在实际操作中,"AutoDeploy"可能是一个包含所有这些功能的脚本文件集合,或者是一个自动...
自动化部署脚本是IT行业中一个重要的实践,它旨在提高效率,减少人为错误,使得软件部署过程更为顺畅。在这个场景中,我们关注的是一个名为"自动化部署脚本"的压缩包,其中包含了实现这一目标的关键文件。这个压缩包...
本文将详细介绍如何使用提供的"jdk1.8自动部署脚本"来快速、便捷地在您的系统上安装JDK 1.8。 首先,让我们了解JDK(Java Development Kit)。JDK是Oracle公司发布的Java编程语言的开发环境,包含了编译器、调试器...
这个"iis部署脚本demo"的压缩包包含了用于自动化IIS部署的一些关键组件,旨在简化和优化网站或应用的发布过程。 首先,让我们来详细了解一下其中的每个文件及其作用: 1. **app_offline.htm**: 这个文件在部署...
这个“jenkins自动化部署脚本.zip”压缩包文件包含了实现Jenkins自动化部署的相关脚本,通过这些脚本,可以极大地提高开发团队的工作效率,减少人为错误,并确保代码的快速迭代和稳定发布。 1. **Jenkins 概述**: ...
关于OpenStack的部署有很多方法和社区项目,笔者公司采用了社区中的kolla项目作为部署OpenStack的方案,本文会详细介绍使用kolla在基于传统企业常用的vlan网络环境下部署OpenStack生产环境的实际案例。
通过以上内容,我们对RabbitMQ部署有了全面的了解,使用提供的部署脚本可以极大地简化这一过程,使你能够快速在本地或生产环境中设置起RabbitMQ服务。记得在实际操作时根据自己的系统环境和需求进行适当调整。
当自动化脚本编写完成并经过初步测试后,接下来的步骤是部署脚本到生产环境并进行监控和调试。在部署过程中,需要关注脚本对系统性能的影响,并进行必要的优化。在监控方面,可以利用Maximo提供的日志功能跟踪脚本...
标题和描述提到的"自动获取SVN代码并编译代码 以及自动部署方案"是一种高效的工作流,它整合了版本控制、编译和部署三个重要环节,使得开发团队能够快速响应变更,减少手动操作带来的错误。以下是关于这个主题的详细...
本文将详细探讨Jenkins Pipeline脚本以及如何利用它进行自动部署。 首先,`Jenkinsfile`是一个文本文件,通常包含Groovy代码,定义了Jenkins Pipeline的逻辑。在`Jenkinsfile.gy`中,你将看到一系列的步骤,如源...
本文将深入探讨如何通过Jenkinsfile脚本来实现多分支流水线的自动化部署。 首先,我们要了解Jenkinsfile。Jenkinsfile是一个文本文件,它定义了Jenkins的工作流或者说是“Pipeline”。这个文件通常放在版本控制系统...
在实验文件中,这个shell脚本应该已经包含了所有必要的命令,只需在CentOS 7环境下运行即可实现自动部署。 **五、安全和优化** 在实际生产环境中,还需要考虑更多的安全因素,如限制Nginx和PHP-FPM的权限,设置...
本文将详细介绍如何编写和执行Redis的自动化部署脚本。 一、环境准备 在开始自动化部署之前,我们需要确保目标服务器具备以下条件: 1. 操作系统:通常选择Linux发行版,如Ubuntu、CentOS等。 2. SSH无密码登录:...
本文将详细讲解如何基于CentOS 7操作系统,使用提供的"zabbix自动安装脚本"来高效地部署Zabbix。 首先,`zabbix_installation.sh`是这个自动安装脚本的核心文件。这个脚本通常包含了执行一系列命令和配置的逻辑,...
Java项目的自动化构建、打包和部署是现代开发流程中的重要环节,极大地提高了开发效率...通过这种方式,Java项目可以实现从代码修改到生产环境部署的无缝自动化流程,降低手动操作出错的可能性,提升开发团队的生产力。
【JBoss 上线部署脚本】是针对JBoss应用服务器的一种自动化管理工具,它整合了一系列命令行操作,用于简化和优化应用的部署流程。在IT运维中,手动执行这些步骤可能会耗时且容易出错,因此,通过编写脚本可以提高...
使用这些工具,开发者可以创建复杂的构建流程,例如:在代码提交后自动触发单元测试、集成测试,如果所有测试都通过,则继续打包应用并部署到预生产或生产环境。 最后,压缩包中的"BuildScript"文件可能是用于演示...
- **无需停机即可部署**:自动化脚本支持动态部署,这意味着企业可以在不影响系统正常运行的情况下,实现新功能的快速部署。 - **减少对Java的依赖**:由于其易用性,用户不再需要依赖Java来实现定制化需求,这大大...
对于生产环境,通常需要对数据库执行有定时备份操作,好方便数据库出现异常问题的数据恢复,提高数据库的安全性,这里提供linux服务器下详细操作脚本,供大家参阅