脚本改造
Posted ipyanthony
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了脚本改造相关的知识,希望对你有一定的参考价值。
##########################Jenkins脚本改造#############################
BUILD_ID=DONTKILLME
#服务名称
SNAME=yutang-study-center-api
NAME=study-center-api
SBAG=yutang-study-center-api-1.0.0-SNAPSHOT.jar
SPORT=9003
SNODE=01
SHELL_DIR=/home/yutang
####################
mv /data/service/${SNAME}/target/* ${SHELL_DIR}/
rm -rf /data/service/${SNAME}/*
cp -r ${SHELL_DIR}/* /data/service/${SNAME}/
rm -rf ${SHELL_DIR}/*
##########################
#cd /data/service/${SNAME}/
#服务启动传参
#第一个参数为服务名称
#第二个参数为服务端口
#第三个参数为节点ID,{--spring.application.node=01}
#使用启动脚本,需要传入三个参数
#重启服务
sleep 10
/bin/bash /data/service/${SNAME}/restart.sh ${SBAG} ${SPORT} ${SNODE} ${NAME}
##################Service启动脚本改造##################################
#!/bin/bash
#kill service pid and starting service
SERVICEname=$1
SERVICEport=$2
SERVICEnode=$3
SERVICENAME=$4
BASEDIR=/data/service
echo "#####################################"
echo "name:${SERVICEname}"
echo "port:${SERVICEport}"
echo "node:${SERVICEnode}"
echo "node:${SERVICENAME}"
echo "#####################################"
# delete service node
curl "http://192.168.2.153:9100/services/manager/remove?name=${SERVICENAME}&node=${SERVICEnode}"
sleep 10
#Stoping Service
pidlist=`ps -ef|grep ${SERVICEname}|grep -v "grep" | grep -v "restart.sh" |grep -v "tail" |awk ‘{print $2}‘`
if [ "$pidlist" = "" ]
then
#echo "Not Find ServicePid"
echo " "
else
kill -9 $pidlist
fi
# Starting Service
echo "####################################################################"
echo "${SERVICEname} is Being started"
#running service
#nohup /data/server/jdk1.8.0_112/bin/java -Xms300m -Xmx300m -jar ${SERVICEname} #--server.port=${SERVICEport} --spring.application.node=${SERVICEnode} > /data/service/logs/${SERVICEname}.log & 2>&1 &
nohup /data/server/jdk1.8.0_112/bin/java -Xms300m -Xmx300m -javaagent:/data/service/pinpoint-agent/pinpoint-bootstrap-1.8.0.jar -Dpinpoint.agentId=${SERVICENAME}-${SERVICEnode} -Dpinpoint.applicationName=${SERVICENAME} -jar ${BASEDIR}/yutang-${SERVICENAME}/${SERVICEname} --server.port=${SERVICEport} --spring.application.node=${SERVICEnode} > /data/service/logs/${SERVICEname}.log & 2>&1 &
sleep 20
#Detection service
Runpid=`ps -ef|grep ${SERVICEname}|grep -v "grep" | grep -v "restart.sh" |grep -v "tail" |awk ‘{print $2}‘`
sleep 10
if [ "$Runpid" = "" ]
then
echo "####################################################################"
echo "Not Find ServicePid"
echo "ServiceNode ${SERVICEnode} Startup faild"
echo "${SERVICEname} is Startup faild"
echo "####################################################################"
exit 1
else
echo "####################################################################"
echo "ServiceNode ${SERVICEnode} Startup success"
echo "${SERVICEname} is Startup success"
echo "service start success"
#rm -rf /home/yutang/*
echo "####################################################################"
exit 0
fi
以上是关于脚本改造的主要内容,如果未能解决你的问题,请参考以下文章