linux下的springboot项目启动文件

启动springboot项目的脚本文件,启动时./startup.sh即可,会先关闭原进程,再启一个新进程。

创建startup.sh

写入内容

 #!/bin/bash

clear  

echo ""

echo "*******************************************************************************************"

echo "****************************Welcome using the Automated scripts****************************"

echo "*******************************************************************************************"

echo ""

echo ""

echo "     ->1|restart test-project          **********        "

echo ""

echo "     ->5|restart all project"

echo ""

echo "*******************************************************************************************"

echo ""

JAVA_HOME=/usr/local/jdk1.8.0_121

JRE_HOME=/usr/local/jdk1.8.0_121/jre

PATH=$PATH:$JAVA_HOME/bin:$JRe_HOME/bin:$TOMCAT_HOME/bin

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

export JAVA_HOME JRE_HOME PATH CLASSPATH

#restart test-project

restartApiv3 () {

    pid=`ps aux | grep test-project-0.1.jar | grep -v grep  | awk '{print $2}'`

    echo $pid

    if [ -n "$pid" ]

        then {

            echo "========kill test-project begin=============="

            echo $pid

            kill -9 $pid

            echo "========kill test-project end=============="

            sleep 2

        }

    fi

    echo "===========startup test-project=============="

    cd /data/www/test/  #jar所在路径

    nohup java -jar -Dspring.profiles.active=qa -Xms256m -Xmx1g /data/www/test/test-project-0.1.jar --server.port=8089 >> /dev/null &    #--server.port=8089这个是动态设置端口,也可不写就会按配置里写的端口

    sleep 12

    pid=`ps aux | grep test-project-0.1.jar | grep -v grep  | awk '{print $2}'`

    echo $pid

    if [ -n "$pid" ]

        then {

             echo " test-project started "

             return 0

        }

    else

        return 1

    fi

}

if [ "$1" != "" ] ; then

    if [ $1 == 1 ] ; then

        restartApiv3

        exit $?

    elif [ $1 == 5 ] ; then

        restartApiv3

        exit $?

    else

        echo "选择有误,再见!~"

    fi

else

    read -p "Enter index number to select: " 

    if [ "${REPLY}" == 1 ] ; then

        restartApiv3

    elif [ "${REPLY}" == 5 ] ; then

        restartApiv3

    else

        echo "选择有误,再见!"

  fi

fi

原文地址:https://www.cnblogs.com/ggooo/p/8580282.html