项目脚本

#!/bin/sh


APP='*'
APP_PATH='*'

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



function start()
{

  rm -f tpid
  nohup java -Xms512m -Xmx1024m -jar ${APP_PATH}/${APP_NAME} >>  ${APP_PATH}/${APP}.log 2>&1 &


  echo $! > ${APP_PATH}"/tpid"

  check


}


function stop()
{


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

   sleep 3
   tpid=`ps -ef|grep $APP_PATH/$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_PATH/$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_PATH/$APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`

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

  fi

}

function logs() 
{
    tail -20f ${APP_PATH}/${APP}.log
}






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

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

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

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