一键部署脚本
最近做银行项目,生产环境我们接触不到,升级部署完全由行方人员按我们的操作文档执行。但是我们不确保他们操作的准确性,所以我们所有的升级一律使用脚本,尽可能减少人为的操作,尽量做到一键升级部署。 下文是我们升级脚本的简化记录,以便以后使用参考。
配置文件–所有因环境因素需要修改的内容
config.init
mysqlIp
=127.0.0.1
mysqlPort
=3306
mysqlUser
=****
mysqlPass
=****
mysqlDataBase
=test
mysqlUpdateSqlPath
=/home/update/update_20191217/mysql_update.sql
zipFilePath
=/home/update/20200318/
zipFile
=backend.zip
serviceName
=realtime
applicationFilePath
=/root/zxzs/
applicationConf1
=http://0.0.0.0:38000/task/process/
applicationConf2
=http://0.0.0.0:18000/entity_recognition/
后台更新脚本
#!/bin/bash
source /etc/profile
source ~/.bash_profile
if [[ $
then
DONEDATE
=$1
else
DONEDATE
=$(date --date='1 days ago' +%Y%m%d)i
fi
source ./config.init
if [[ $? = 1
]];
then
echo -e
"\n read config failure;please check ./config.ini"
exit
fi
cd ${applicationFilePath}
echo -e
"\n==== I will stop ${serviceName} server :===="
ps -ef
|grep "${serviceName}"
rtn
=`ps -ef |grep "${serviceName}" | wc -l `
if [[ $rtn = 1
]];
then
echo -e
"\n ${serviceName} server is not start"
else
ps -ef
|grep "${serviceName}" | grep -v
grep | awk '{print $2}' | xargs kill -9
fi
rtn
=`ps -ef |grep "${serviceName}" | wc -l `
if [[ $rtn = 1
]];
then
echo -e
"\n stop ${serviceName} server success."
fi
echo -e
"\n start back application file"
backFilePath
=${DONEDATE}'bak'
mkdir ${backFilePath}
cp realtime*.jar ./
${backFilePath}/
cp ./lib/smartv-*.jar ./
${backFilePath}/
rm realtime*.jar
rm ./lib/smartv-complier*.jar
echo -e
"\n bak application jar file success"
cp conf/qualityInspection.properties ./
${backFilePath}/
echo -e
"\n bak application jar file success"
echo -e
"\n start update application"
echo "nlp.task.pathurl=${applicationConf1}">>conf/qualityInspection.properties
echo "nlp.rule.url=${applicationConf2}">>conf/qualityInspection.properties
echo "quality.emotion.type=1">>conf/qualityInspection.properties
echo -e
"\n update application conf success"
echo -e
"\n==== will copy unzip file===="
cd $zipFilePath
unzip
$zipFile
echo -e
"\n==== will update ${serviceName}===="
cd ${applicationFilePath}
cp $zipFilePath/realtime*.jar ./
cp $zipFilePath/smartv-complier*.jar ./lib/
rm -rf
$zipFilePath/realtime*.jar
rm -rf
$zipFilePath/smartv-complier*.jar
build_dir
="logs"
if [ ! -d
"$build_dir" ]; then
mkdir $build_dir
fi
echo -e
"\n start application service ......"
nohup java -jar realtime*.jar conf voiceAsynETL y
> ./logs/voiceAsynETL.log
&
if [[ $? == 0
]];
then
echo -e
"\n voiceAsynETL 服务 start success"
sleep 3
else
echo -e
"\n voiceAsynETL 服务 start failure."
exit 1
fi
nohup java -jar realtime*.jar conf voiceqi y
> ./logs/voiceqi.log
&
if [[ $? == 0
]];
then
echo -e
"\n voiceqistart success"
sleep 3
else
echo -e
"\n voiceqi start failure."
exit 1
fi
nohup java -jar realtime*.jar conf voiceTextExtract y
> ./logs/voiceTextExtract.log
&
if [[ $? == 0
]];
then
echo -e
"\n voiceTextExtract start success"
sleep 3
else
echo -e
"\n voiceTextExtract start failure."
exit 1
fi
nohup java -jar realtime*.jar conf voiceExtract y
> ./logs/voiceExtract.log
&
if [[ $? == 0
]];
then
echo -e
"\n voiceExtract start success"
sleep 3
else
echo -e
"\n voiceExtract start failure."
exit 1
fi
sleep 5
exit
回滚脚本
#!/bin/bash
source /etc/profile
source ~/.bash_profile
if [[ $
then
DONEDATE
=$1
else
DONEDATE
=$(date --date='1 days ago' +%Y%m%d)i
fi
source ./config.ini
if [[ $? = 1
]];
then
echo -e
"\n read config failure;please check ./config.ini"
exit
fi
echo -e
"\n==== will return file===="
cd ${applicationFilePath}
backFilePath
=${DONEDATE}'bak'
if [ ! -d
"$backFilePath" ];
then
echo -e
"\n==== file is return success===="
else
rm -rf ./
${backFilePath}/realtime*.jar
rm -rf ./
${backFilePath}/smartv-complier*.jar
cp ./
${backFilePath}/realtime*.jar ./
cp ./
${backFilePath}/*.properties ./conf/
cp ./
${backFilePath}/smartv-complier*.jar ./lib/
echo -e
"\n==== file is return success===="
rm -rf ./
${backFilePath}
fi
rm -rf
$zipFilePath/*.jar
rtn
=`ps -ef |grep "${serviceName}" | wc -l `
if [[ $rtn = 1
]];
then
echo -e
"\n start run old service====="
nohup java -jar realtime*.jar conf voiceAsynETL y
> ./logs/voiceAsynETL.log
&
nohup java -jar realtime*.jar conf voiceqi y
> ./logs/voiceqi.log
&
nohup java -jar realtime*.jar conf voiceTextExtract y
> ./logs/voiceTextExtract.log
&
nohup java -jar realtime*.jar conf voiceExtract y
> ./logs/voiceExtract.log
&
exit
else
echo -e
"\n service is running ====="
fi
前台更新脚本
#!/bin/bash
source /etc/profile
source ~/.bash_profile
if [[ $
then
DONEDATE
=$1
else
DONEDATE
=$(date --date='1 days ago' +%Y%m%d)i
fi
source ./config.ini
if [[ $? = 1
]];
then
echo -e
"\n read config failure;please check ./config.ini"
exit
fi
echo -e
"\n==== will stop service===="
ps -ef
|grep "${tomcatPath}"
rtn
=`ps -ef |grep "${tomcatPath}" | wc -l `
if [[ $rtn = 2
]];
then
ps -ef
|grep "${tomcatPath}" | grep -v
grep | awk '{print $2}' | xargs kill -9
if [[ $? == 0
]];
then
echo -e
"\n stop ${tomcatPath} server success"
sleep 3
else
echo -e
"\n stop ${tomcatPath} server failure. Please run: ps -ef |grep \"${tomcatPath}\" | grep -v grep | awk '{print $2}' | xargs kill -9"
exit
fi
fi
rtn
=`ps -ef |grep "${tomcatPath}" | wc -l `
if [[ $rtn = 1
]];
then
echo -e
"\n"
else
echo -e
"\n stop ${tomcatPath} server failure. Please run: ps -ef |grep \"${tomcatPath}\" | grep -v grep | awk '{print $2}' | xargs kill -9"
exit
fi
cd $zipFilePath
unzip
${zipFile}
cd $applicationFilePath
backFilePath
=${DONEDATE}'bak/'
mkdir $backFilePath
cp -rf ./ROOT
$backFilePath/
echo -e
"\n==== bak file success===="
rm -rf ./ROOT/js
rm -rf ./ROOT/pages
rm -rf ./ROOT/lib/realtime*.jar
rm -rf ./ROOT/classes
cp -rf
$zipFilePath/js ./ROOT/
cp -rf
$zipFilePath/pages ./ROOT/
cp -rf
$zipFilePath/lib ./ROOT/WEB-INF/
cp -rf
$zipFilePath/classes ./ROOT/WEB-INF/
echo -e
"\n==== update application file success===="
$tomcatPath/bin/startup.sh
echo -e
"\n==== tail -100f ${tomcatPath}/logs/catalina.out===="
sleep 15
tail -100
${tomcatPath}/logs/catalina.out
sleep 5
exit 0
前台回滚脚本
source /etc/profile
source ~/.bash_profile
if [[ $
then
DONEDATE
=$1
else
DONEDATE
=$(date --date='1 days ago' +%Y%m%d)i
fi
source ./config.ini
if [[ $? = 1
]];
then
echo -e
"\n read config failure;please check ./config.ini"
exit
fi
echo -e
"\n==== will stop service===="
ps -ef
|grep "${tomcatPath}"
rtn
=`ps -ef |grep "${tomcatPath}" | wc -l `
if [[ $rtn = 2
]];
then
ps -ef
|grep "${tomcatPath}" | grep -v
grep | awk '{print $2}' | xargs kill -9
if [[ $? == 0
]];
then
echo -e
"\n stop ${tomcatPath} server success"
sleep 3
else
echo -e
"\n stop ${tomcatPath} server failure. Please run: ps -ef |grep \"${tomcatPath}\" | grep -v grep | awk '{print $2}' | xargs kill -9"
exit
fi
fi
rtn
=`ps -ef |grep "${tomcatPath}" | wc -l `
if [[ $rtn = 1
]];
then
echo -e
"\n"
else
echo -e
"\n stop ${tomcatPath} server failure. Please run: ps -ef |grep \"${tomcatPath}\" | grep -v grep | awk '{print $2}' | xargs kill -9"
exit
fi
cd $applicationFilePath
backFilePath
=${DONEDATE}'bak/'
if [ ! -d
"$backFilePath" ]; then
rm -rf ROOT
cp -rf
$backFilePath/ROOT ./
sleep 10
fi
rm -rf
$backFilePath
echo -e
"\n==== bakfile return success===="
rm -rf
$zipFilePath/js
rm -rf
$zipFilePath/pages
rm -rf
$zipFilePath/lib
rm -rf
$zipFilePath/classes
$tomcatPath/bin/startup.sh
echo -e
"\n==== tail -100f ${tomcatPath}/logs/catalina.out===="
sleep 15
tail -100
${tomcatPath}/logs/catalina.out
sleep 5
exit 0