shell脚本之发布-创新互联
#!/bin/bash
PATH=/application/jdk/bin:/application/jdk/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
REMOTE=/home/qroot/shangxian
LOCAL_HOST=/home/qroot/shangxian
LOG_CDATE='date "+%Y-%m-%d"'
LOG_CTIME='date "+%H:%M:%S"'
CDATE=$(date "+%Y-%m-%d")
CTIME=$(date "+%H-%M-%S")
SHELL_NAME="deployment_bigdata.sh"
SHELL_DIR="/home/qroot"
SHELL_LOG="${SHELL_DIR}/${SHELL_NAME}.log"
LOCK_FILE="/tmp/deploy_bigdata.lock"
#mkdir -p /home/qroot/shangxian/bigdata/{new_word,old_word,tmp,formal,config/{nginx,replace}}
usage(){
echo "USAGE:$0 AGE{bigdata [bigdata.tar.gz]|10.28.53.{192,223}] }"
}
shell_lock(){
touch $LOCK_FILE
}
shell_unlock(){
rm -f $LOCK_FILE
}
writelog(){
LOGINFO=$1
echo "${LOG_CDATE} ${LOG_CTIME}: ${SHELL_NAME} : ${LOGINFO} " >> ${SHELL_LOG}
}
tq_tomcat_docker(){
sudo sh -x /application/tomcat/bin/shutdown.sh
PD_1=$(sudo ps -ef|grep '/application/tomcat/bin'|grep -v 'grep'|wc -l)
sleep 30
if [ ${PD_1} -gt 0 ]
then
PID_1=$(sudo ps -ef|grep '/application/tomcat/bin'|grep -v 'grep'|awk 'NR==1{print $2}')
sudo kill -9 ${PID_1}
fi
sleep 5
sudo mkdir -p /application/tomcat/old_logs/logs_${CDATE}
sudo mv /application/tomcat/logs/* /application/tomcat/old_logs/logs_${CDATE}/
cd /application/tomcat/work/Catalina/ && sudo rm -fr *
sudo su - tomcat -c "sh /application/tomcat/bin/startup.sh"
}
docker_bigdata_scp() {
writelog "docker_bigdata_scp"
[ ! -d ${LOCAL_HOST}/bigdata/new_word ] && echo "${LOCAL_HOST}/bigdata/new_word ---bucunzai" && exit 16
if [ -f "${LOCAL_HOST}/bigdata/new_word/${1}" ]
then
echo "$(ls ${LOCAL_HOST}/bigdata/new_word/${1})"
mv ${LOCAL_HOST}/bigdata/new_word/${1} ${LOCAL_HOST}/bigdata/new_word/bigdata_"$CDATE"-${CTIME}.war || exit 16
if [ -f "${LOCAL_HOST}/bigdata/new_word/bigdata_"$CDATE"-${CTIME}.war" ]
then
echo "$(ls ${LOCAL_HOST}/bigdata/new_word/bigdata_"$CDATE"-${CTIME}.war)"
else
echo "bigdata_"$CDATE"-${CTIME}.war -- File does not exist" && exit 11
fi
else
echo "${1}--File does not exist" && exit 10
fi
}
docker_bigdata_tar() {
writelog "docker_bigdata_tar"
PD_1=$(ls ${REMOTE}/bigdata/new_word/bigdata_"$CDATE"-${CTIME}.war 2>/dev/null|wc -l)
if [ ${PD_1} -ne 0 ]
then
cd /application/tomcat/web_tmp/ && sudo rm -fr *
sudo unzip ${LOCAL_HOST}/bigdata/new_word/bigdata_"$CDATE"-${CTIME}.war -d /application/tomcat/web_tmp/bigdata_"$CDATE"-${CTIME}
mv ${REMOTE}/bigdata/new_word/bigdata_"$CDATE"-${CTIME}.war ${REMOTE}/bigdata/old_word/
cd ${REMOTE}/bigdata/new_word/ && sudo rm -fr *
cd /application/tomcat/webapps/ && sudo rm -fr *
sudo ln -s /application/tomcat/web_tmp/bigdata_"$CDATE"-${CTIME} /application/tomcat/webapps/bigdata_new
sudo chmod -R +x /application/tomcat/webapps/bigdata_new/*
sudo chown -R tomcat.tomcat /application/tomcat
sudo chown -R tomcat.tomcat /application/tomcat/*
sudo chmod -R +x /application/tomcat/webapps/bigdata/WEB-INF/classes/com/*
else
echo ${1}-bigdata_"$CDATE"-${CTIME}.war -- File does not exist && exit 12
fi
}
replace_config() {
writelog "config"
PD_2=$(ls ${REMOTE}/bigdata/config/replace/bigdata/* 2>/dev/null|wc -l)
if [ ${PD_2} -gt 0 ]
then
sudo \cp ${REMOTE}/bigdata/config/replace/bigdata/* /application/tomcat/webapps/bigdata_new/WEB-INF/classes/config/db/
else
echo "replace===$(ls ${REMOTE}/bigdata/config/replace/* 2>/dev/null|wc -l)"
fi
}
huizong(){
if [ -f $LOCK_FILE ];then
echo "Deploy is running" && exit;
fi
TAR_NAME=${2}
CASE=${1}
case "${CASE}" in
bigdata)
shell_lock
docker_bigdata_scp ${TAR_NAME}
sleep 10
docker_bigdata_tar
sleep 10
replace_config
sleep 10
tq_tomcat_docker
shell_unlock
;;
*)
usage
exit 3
esac
}
mian(){
CMD_1=$1
CMD_2=$2
huizong $CMD_1 $CMD_2
}
mian ${1} ${2}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
作为一家“创意+整合+营销”的成都网站建设机构,我们在业内良好的客户口碑。创新互联提供从前期的网站品牌分析策划、网站设计、做网站、网站制作、创意表现、网页制作、系统开发以及后续网站营销运营等一系列服务,帮助企业打造创新的互联网品牌经营模式与有效的网络营销方法,创造更大的价值。分享题目:shell脚本之发布-创新互联
分享路径:http://pwwzsj.com/article/djcopg.html