#!/bin/sh
SYSTEM_CODE=transport
PROGRAM_PATH=/opt/api
BACKUP_PATH=/opt/api/backup
PACKAGE_NAME=asc-${SYSTEM_CODE}.jar
PROGRAM_FULL_PATH=$PROGRAM_PATH/$PACKAGE_NAME
script_dir=$(dirname $0)
source_dir=$script_dir/asc-server
old_pwd=$(pwd)
cd $source_dir
# 更新代码
echo 准备进行 git pull ...
if ! git pull ; then
echo 无法更新代码,将使用老版本代码进行打包
fi
echo git pull 完成,准备进行 mvn package
# 编译打包
if ! mvn package -Dmaven.test.skip=true -pl asc-applications/asc-${SYSTEM_CODE}/asc-${SYSTEM_CODE}-api -am ; then
code=$?
echo 【出错】编译失败,退出脚本
exit $code
fi
echo mvn package 完成,准备进行包的备份、复制
# 发布
if ! mv ${PROGRAM_FULL_PATH} $BACKUP_PATH/$PACKAGE_NAME ; then
echo 不进行备份
else
echo 备份 ${PROGRAM_FULL_PATH} 到 $BACKUP_PATH/$PACKAGE_NAME
fi
if ! cp asc-applications/asc-${SYSTEM_CODE}/asc-${SYSTEM_CODE}-api/target/$PACKAGE_NAME ${PROGRAM_FULL_PATH} ; then
echo 复制失败了,请确认文件名是否正确
exit 1
fi
echo 包备份和启动完成,准备启动
# 启动
echo 尝试停用 asc-${SYSTEM_CODE} 的现有进程...
if ps -ef |grep asc-${SYSTEM_CODE} | grep -v grep |awk '{print $2}' |xargs kill; then
sleep 1;
echo 关闭了之前的 sys-${SYSTEM_CODE} 进程
else
echo 没找到之前的 sys-${SYSTEM_CODE} 进程
fi
echo "执行命令 nohup java -jar ${PROGRAM_FULL_PATH} -Dspring.profiles.active=dev 2>&1 > ${PROGRAM_PATH}/asc-${SYSTEM_CODE}.nohup"
nohup java -jar ${PROGRAM_FULL_PATH} -Dspring.profiles.active=dev 2>&1 > ${PROGRAM_PATH}/asc-${SYSTEM_CODE}.nohup &
sleep 0.1
echo 可能已经启动,日志输出位于 ${PROGRAM_PATH}/asc-${SYSTEM_CODE}.nohup
echo 将自动进行 tail, 按 Ctrl + C 结束 tail
tail -fn0 ${PROGRAM_PATH}/asc-${SYSTEM_CODE}.nohup