linux启动springboot服务,关闭并备份原有服务,启动新的服务

linux启动springboot服务 sh脚本

#!/bin/sh
# 定义变量
BASE_DIR=/usr/local/ctms/server
APP_NAME=ctms-system.jar
JAVA_OPTS="-Xms512m -Xmx1024m"
CONFIG_FILE=application.yml
BACKUP_DIR=backup
#脚本菜单项
usage(){
 echo "Usage: sh 脚本名.sh [start|stop|restart|status]"
 exit 1
}
is_exist(){
 pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
 #如果不存在返回1,存在返回0
 if [ -z "${pid}" ]; then
 return 1
 else
 return 0
 fi
}
#启动脚本
start(){
 is_exist
 if [ $? -eq "0" ]; then
 echo "${APP_NAME} is already running. pid=${pid} ."
 else
# 备份jar包
 cp -p $APP_NAME $BACKUP_DIR/$APP_NAME.$(date +%Y%m%d%H%M%S)
#此处注意修改jar和log文件文件位置:
 nohup java -jar $BASE_DIR/$APP_NAME --spring.config.location=$CONFIG_FILE > bootdolog.file   2>&1 &
#此处打印log日志:
# tail -f /home/clkt/KeAndScExtract/bootdolog.file
 fi
}
#停止脚本
stop(){
 is_exist
 if [ $? -eq "0" ]; then
 kill -9 $pid
 else
 echo "${APP_NAME} is not running"
 fi
}
#显示当前jar运行状态
status(){
 is_exist
 if [ $? -eq "0" ]; then
 echo "${APP_NAME} is running. Pid is ${pid}"
 else
 echo "${APP_NAME} is NOT running."
 fi
}
#重启脚本
restart(){
 stop
 start
}
case "$1" in
 "start")
 start
 ;;
 "stop")
 stop
 ;;
 "status")
 status
 ;;
 "restart")
 restart
 ;;
 *)
 usage
 ;;
esac

执行脚本提示syntax error near unexpected token $'{\r''

如果通过sh 命令 启动报错syntax error near unexpected token $'{\r''
说明脚本换行符存在问题,可以通过执行
sed -i ‘s/\r//g’ ctms-server-start.sh`

你可能感兴趣的:(自用脚本,java,linux,linux,spring,boot,java)