SpringBoot启动脚本

原创
2022/01/24 14:41
阅读数 126

 

需要修改如下:

springboot的存放路径:APP_DIR=
springboot的应用名称:APP_NAME=
springboot的配置文件:APP_CONF=$APP_DIR/application.yml
jdk的home路径:export JAVA_HOME=



创建app.sh内容如下:
chmod +x app.sh



启动:     ./app.sh start

停止:     ./app.sh stop

强制关闭:  ./app.sh kills

部署:      ./app.sh deploy

 

#!/bin/sh
#
#
### springboot的服务路径
APP_DIR=/opt/software/mydata/projar/database-dictionary
### springboot的服务名称
APP_NAME=database-dictionary-1.0-SNAPSHOT
APP_CONF=$APP_DIR/application.yml
 
#set java home
export JAVA_HOME=/opt/software/jdk8
 
usage() {
    echo "Usage: sh eju-micro-app.sh [start|stop|deploy]"
    exit 1
}
 
kills(){
    tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
    if [[ $tpid ]]; then
        echo 'Kill Process!'
        kill -9 $tpid
    fi
}
 
start(){
    rm -f $APP_DIR/tpid
    #nohup java -jar myapp.jar --spring.config.location=application.yml > /dev/null 2>&1 &
    nohup java  -Xms800m -Xmx800m -XX:PermSize=256m -XX:MaxPermSize=512m -XX:MaxNewSize=512m -jar -Dfile.encoding=utf-8 $APP_DIR/"$APP_NAME".jar > nohup.out 2>&1 &
    echo $! > $APP_DIR/tpid
    echo Start Success!
}
 
stop(){
        tpid1=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
    echo tpid1-$tpid1
        if [[ $tpid1 ]]; then
        echo 'Stop Process...'
        kill -15 $tpid1
    fi
    sleep 5
    tpid2=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
        echo tpid2-$tpid2
    if [[ $tpid2 ]]; then
        echo 'Kill Process!'
        kill -9 $tpid2
    else
        echo 'Stop Success!'
    fi
 
}
 
check(){
    tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
    if [[ tpid ]]; then
        echo 'App is running.'
    else
        echo 'App is NOT running.'
    fi
}
 
deploy() {
    kills
    rm -rf $APP_DIR/"$APPNAME".jar
    cp "$APP_NAME".jar $APP_DIR
}
 
case "$1" in
    "start")
        start
        ;;
    "stop")
        stop
        ;;
    "kill")
        kills
        ;;
    "deploy")
        deploy
        ;;
    *)
        usage
        ;;
esac

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部