springboot linux下启动的脚本

看到比较好的linux脚本:

start.sh

#!/bin/sh

rm -f tpid

nohup java -jar xx.jar --spring.profiles.active=dev > /dev/null 2>&1 &

echo $! > tpid

echo Start Success!

stop.sh

#!/bin/sh
APP_NAME=myapp

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Stop Process...'
    kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
else
    echo 'Stop Success!'
fi

check.sh

#!/bin/sh
APP_NAME=myapp

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

kill.sh

#!/bin/sh
APP_NAME=myapp

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

以上合并为一个脚本:

#!/bin/sh


APP=stockhouse

APP_NAME=${APP}".jar"
command=$1



function start()
{

  rm -f tpid

  nohup java -jar ${APP_NAME} > /dev/null 2>&1 &

  echo $! > tpid

  check


}


function stop()
{

  tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
  if [ ${tpid} ]; then
     echo 'Stop Process...'
     kill -15 $tpid
   fi

   sleep 5
   tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`

   if [ ${tpid} ]; then
      echo 'Kill Process!'
      kill -9 $tpid
    else
      echo 'Stop Success!'
    fi
}


function 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

}



function forcekill()
{
  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

}






if [ "${command}" ==  "start" ]; then
    start

elif [ "${command}" ==  "stop" ]; then
     stop

elif [ "${command}" ==  "check" ]; then
     check

elif [ "${command}" ==  "kill" ]; then
     forcekill
else
    echo "Unknow argument...."
fi

猜你喜欢

转载自my.oschina.net/huhaoren/blog/1794122