#!/usr/bin/bash
# 开发环境的部署脚本,没有回滚和判断是否已发布
DATE=$(date +%Y-%m-%d-%H-%M-%S)
TARGET_SERVER="10.1.11.110"
SOURCE_DIR=/opt
TARGET_DIR=/data/yesway-cloud/${JOB_NAME}
# 使用了git parameters插件
NAME=${DATE}-${git_branch/\//-}
# 进入工作目录
cd_workspace() {
cd ${WORKSPACE}
}
# 部署
scp_server() {
for hosts in $TARGET_SERVER
do
# 拷贝到目标机
echo 'copy to target server......'
scp target/*.jar root@${hosts}:/opt/${NAME}.jar
ssh root@${hosts} "mkdir -p ${TARGET_DIR}/${NAME} && \
mv /opt/${NAME}.jar ${TARGET_DIR}/${NAME} && \
rm -f ${TARGET_DIR}/${JOB_NAME}.jar && \
ln -s ${TARGET_DIR}/${NAME}/${NAME}.jar ${TARGET_DIR}/${JOB_NAME}.jar"
echo 'copy success.'
# 关闭.jar程序(脚本在下面)
echo 'shutdown......'
ssh root@${hosts} "/scripts/shutdown.sh ${JOB_NAME}.jar"
echo 'shutdown success.'
# 启动.jar程序(脚本在下面)
echo 'start......'
ssh root@${hosts} "/scripts/start.sh ${TARGET_DIR} ${JOB_NAME}.jar test"
echo 'start success.'
done
}
deploy() {
cd_workspace
scp_server
}
deploy
shutdown.sh
#!/usr/bin/bash
PID=$(ps -ef | grep ${1} | grep -v $0 |grep -v grep |awk '{print $2}')
if [ -z "${PID}" ]; then
echo '程序未启动,无需停止进程'
else
for ID in ${PID}
do
echo ${ID}
kill -9 ${ID}
done
fi
start.sh
#!/usr/bin/bash
cd ${1}
source /etc/profile
nohup java -jar ${2} --spring.profiles.active=${3} >/dev/null 2>&1 &
来源:oschina
链接:https://my.oschina.net/u/2450666/blog/3188981