但是在生产环境测的时候,却发现不同环境还稍微有点小的问题。
因为之前旧的不同版本略有小的差异导致;之后经过优化,重新测试OK。
优化点主要是这两点,另外有点其他的小调整:
1.使用ln软连接方式,而不是mv版本号;
2.修改stop服务步骤,kill进程有效性;
在这里,重新补充一下最新的Scripts,如下:
boxagent@iZ2zeed4f6hbydt2078ddcZ:~$ cat boxrelease/script/upgrade_osprey.sh
#!/bin/sh #config APP_NAME=osprey USER_HOME=/home/lifeccp/webapp RELEASE_SRC="boxagent@smith.lifeccp.com:/home/boxagent/boxrelease/osprey/*.zip" #function say() { echo -e "[Osprey Deploy] $0: $1" } fetch_artifacts() { DEST="$USER_HOME/incoming/${APP_NAME}/" [ -d ${DEST} ] || mkdir -p ${DEST} say "Fetching artifacts from $ARTIFACTS_SRC to ${DEST}" scp ${RELEASE_SRC} ${DEST} say "Unzip the new war" cd ${DEST} && unzip -qo *.zip say "Change startup started" sed -i 8d ${USER_HOME}/${APP_NAME}/startup sed -i '8i MAIN_JAR=osprey.release.jar' ${USER_HOME}/${APP_NAME}/startup say "Change startup finished" if [ "$?" = "0" ]; then say "\033[32m -=Fetch artifacts finished=- \033[0m" else say "\033[31m -=Fetch artifacts failed=- \033[0m" exit 1 fi } stop_app() { say "Stopping [${APP_NAME}]" pkill -f ${APP_NAME} osprey_pid=$(pgrep -f ${APP_NAME}) if [ "${osprey_pid}" = "" ]; then say "\033[32m -=Stop ${APP_NAME} finished=- \033[0m" else say "\033[32m -=Stop ${APP_NAME} failed=- \033[0m" kill -9 "${osprey_pid}" kill -9 `ps aux | grep osprey | awk '{print $2}'` say "\033[32m -=Kill -9 ${APP_NAME}=- \033[0m" fi say "Stopping [${APP_NAME}] finished" } backup_app() { DEST="$USER_HOME/archive/${APP_NAME}$(date '+%Y%m%d%H%M')/" say "make backup dir ${DEST}" mkdir -p "${DEST}" cp -r ${USER_HOME}/${APP_NAME}/* ${DEST} say "\033[32m -=Backup ${APP_NAME} finished=- \033[0m" } deploy_app() { DEST="$USER_HOME/incoming/${APP_NAME}" say "Deploy ${APP_NAME}" say "Remove old app" rm -rf $USER_HOME/$APP_NAME/osprey*.release.jar rm -rf $USER_HOME/$APP_NAME/osprey*.release.jar.original say "Copying new app start" cp ${DEST}/osprey*.release.jar $USER_HOME/$APP_NAME/ cp ${DEST}/osprey*.release.jar.original $USER_HOME/$APP_NAME/ say "Copying new app finished" say "Make app link start" ln -s /home/lifeccp/webapp/osprey/osprey-*.release.jar /home/lifeccp/webapp/osprey/osprey.release.jar say "Make app link finished" if [ "$?" = "0" ]; then say "\033[32m -=Deploy ${APP_NAME} finished=- \033[0m" else say "\033[31m -=Deploy ${APP_NAME} failed=- \033[0m" exit 1 fi } clear() { say "clear $USER_HOME/incoming/${APP_NAME}/" rm -rf $USER_HOME/incoming/${APP_NAME}/* } start_app() { say "Start [${APP_NAME}]" sudo reboot if [ "$?" = "0" ]; then say "\033[32m -=Start reboot finished=- \033[0m" else say "\033[31m -=Start reboot failed=- \033[0m" exit 1 fi } publish() { say "********Step1 start..." fetch_artifacts say "********Step1 finished...\n\n********Step2 start..." stop_app say "********Step2 finished...\n\n********Step3 start..." backup_app say "********Step3 finished...\n\n********Step4 start..." deploy_app say "********Step4 finished...\n\n********Step5 start..." clear say "********Step5 finished...\n\n********Step6 start..." start_app say "********Step6 finished...Upgrade finished!" } #### do it ### publish
脚本使用方法:
1.使用ssh方式登录agent被控机;
2.执行如下命令;
scp boxagent@smith.lifeccp.com:/home/boxagent/boxrelease/script/upgrade_osprey.sh .
3.输入密码;
4.等待reboot;
升级完成之后,可以自己查看服务是否正常,一般情况下,没什么问题。
本文转自 念槐聚 博客园博客,原文链接:http://www.cnblogs.com/haochuang/p/6598140.html,如需转载请自行联系原作者