shell编译部署java项目自动化脚本
shell编译部署java项目自动化脚本
半张一块 发表于6个月前
shell编译部署java项目自动化脚本
  • 发表于 6个月前
  • 阅读 26
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

摘要: shell编译部署java项目自动化脚本
green='\e[0;32m' # 绿色  
NC='\e[0m' # 没有颜色
#TUES_WEBSERVER_PID=$(ps x|grep /home/admin/tues-webserver/tues-webserver/target/tues-webserver-0.0.1-SNAPSHOT.jar |awk '{print $1}')
TUES_WEBSERVER_PID=$(cat /home/admin/sh/tues-webserver.pid)
if [ -n "$TUES_WEBSERVER_PID" ]
then
        echo 'kill '$TUES_WEBSERVER_PID
        kill $TUES_WEBSERVER_PID
fi
echo 'start update tues-weberser project'
cd /home/admin/tues-webserver
git pull origin master
echo 'start build tues-webserver project'
cd /home/admin/tues-webserver/tues-webserver
mvn install
cd /home/admin/tues-webserver/tues-webserver/target
echo 'start deploy tues-webserver project'
nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8002,suspend=n -jar /home/admin/tues-webserver/tues-webserver/target/tues-webserver-0.0.1-SNAPSHOT.jar --spring.profiles.active=online > /home/admin/logs/start.log 2>&1 &
echo $! > /home/admin/sh/tues-webserver.pid

START_TIME=`date +%s`
while [[ -z `netstat -ln|grep 9002` ]]
do
        TIME_TOTAL=$[`date +%s`-START_TIME]
        printf "\r" $b $i
        echo -n "[tues-webserver] the server is starting :$TIME_TOTAL S  "
        sleep 1
done
echo -e "\n${green}[tues-webserver] the tuew-webserver start finihed${NC}"



SVN版本
GREEN='\e[0;32m' # 绿色
NC='\e[0m' # 没有颜色

echo "${GREEN}start update cos project${NC}"
cd /usr/local/java/workspace/ycl-platform
svn update
echo -e "${GREEN}start build cos project${NC}"
cd /usr/local/java/workspace/ycl-platform
mvn package -Dmaven.test.skip=true
echo -e "${GREEN}stop cos project${NC}"
PID=$(cat /usr/local/java/sh/cos.pid)
echo "kill PID=$PID"
kill -9 $PID
cd /usr/local/java/workspace/ycl-platform/ycl-web/ycl-cos/target
echo -e "${GREEN} copy cos project ${NC}"
cp -rf ycl-cos /usr/local/java/tomcat/cos/webapps
cd /usr/local/java/tomcat/cos/bin
sh catalina.sh start
START_TIME=`date +%s`
while [[ -z `curl –connect-timeout 1 -m 1 http://localhost:8115/ -s` ]]
do
        TIME_TOTAL=$[`date +%s`-START_TIME]
        printf "\r" $b $i
        echo -en "${GREEN}[cos] the server is starting :$TIME_TOTAL S  ${NC}"

done
echo $(ps -ef|grep cos|awk '{print $2}') > /usr/local/java/sh/cos.pid
PID_STR=$(cat /usr/local/java/sh/cos.pid)
PID=$(echo ${PID_STR%% *})
echo $PID > /usr/local/java/sh/cos.pid
echo -e "\n${GREEN}[cos] the server start finihed${NC}"


#########################2017.10.30
#!/bin/sh
GREEN='\e[0;32m' # 绿色
NC='\e[0m' # 没有颜色

PROJECT_NAME='COS' #项目名称
PROJECT_PID_ROUTE='/usr/local/java/sh/cos.pid' #项目PID文件路径
PROJECT_WORKSPACE='/usr/local/java/workspace/ycl-platform' #项目工程路径
PROJECT_BULID_WORKSPACE='/usr/local/java/workspace/ycl-platform/ycl-web/ycl-cos/target' #项目编译后的文件夹路径
PROJECT_BULID_FOLDER_NAME='ycl-cos' #项目编译后的文件夹名称
PROJECT_START_WORKSPACE='/usr/local/java/tomcat/cos/webapps' #项目运行的文件夹路径
PROJECT_TOMCAT_BIN_FOLDER='/usr/local/java/tomcat/cos/bin' #项目启动的tomcat/bin目录
PROJECT_CONNECT_URL='http://localhost:8115/' #项目本地访问路径-用于检测项目是否启动成功


echo "${GREEN}[ $PROJECT_NAME ] project start update${NC}"
cd $PROJECT_WORKSPACE
svn update
echo -e "${GREEN}[ $PROJECT_NAME ] project start build${NC}"
mvn package -Dmaven.test.skip=true
rc=$?
if [[ $rc -ne 0 ]] ; then
echo -en  "${GREEN}[ $PROJECT_NAME ]
#######################################################
#                      打包失败                        #       
####################################################### ${NC}
"
cd -
exit $rc
fi

echo -e "${GREEN}[ $PROJECT_NAME ] project stop${NC}"
echo $(ps -ef|grep cos|awk '{print $2}') > $PROJECT_PID_ROUTE
PID_NULL_NUMBER=$(grep -o ' ' $PROJECT_PID_ROUTE |wc -l)
if [ "$PID_NULL_NUMBER" -ge '1' ];then
PID_STR=$(cat $PROJECT_PID_ROUTE)
PID=$(echo ${PID_STR%% *})
echo $PID > $PROJECT_PID_ROUTE
echo "kill PID=$PID"
PID=$(cat $PROJECT_PID_ROUTE)
kill -9 $PID
fi

echo -e "${GREEN}[ $PROJECT_NAME ] project clean${NC}"
cd $PROJECT_START_WORKSPACE
rm -rf $PROJECT_BULID_FOLDER_NAME
cd $PROJECT_BULID_WORKSPACE
echo -e "${GREEN}[ $PROJECT_NAME ] project copy${NC}"
cp -rf $PROJECT_BULID_FOLDER_NAME $PROJECT_START_WORKSPACE
cd $PROJECT_TOMCAT_BIN_FOLDER
sh catalina.sh start
START_TIME=`date +%s`
while [[ -z `curl –connect-timeout 1 -m 1 $PROJECT_CONNECT_URL -s` ]]
do
	TIME_TOTAL=$[`date +%s`-START_TIME]
	printf "\r" $b $i
	echo -en  "${GREEN}
###########################################################################################
#																						  #
#																						  #
#       [ $PROJECT_NAME ] project the server is starting :$TIME_TOTAL S                   #
#																						  #
#																						  #
########################################################################################### ${NC}
"
done
echo -e "\n${GREEN}[ $PROJECT_NAME ] project the server start finihed${NC}"


 

标签: shell
共有 人打赏支持
粉丝 23
博文 37
码字总数 33091
作品 2
×
半张一块
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: