当前位置:   article > 正文

linux 分布式执行jar包shell脚本_usage: sh 脚本名.sh [start|stop|restart|status]

usage: sh 脚本名.sh [start|stop|restart|status]

#!/bin/sh

APP_NAME=sms-service

JAR_PATH='/home/ap/t_jar'

JAR_NAME=*.jar

LOG_PATH='/home/ap/t_jar/okdata/logs/session'

usage() {
    echo "Usage: sh sms.sh [start|stop|restart|status]"
    exit 1
}
is_exist(){
  pid=`ps -ef|grep $JAR_NAME|grep -v grep|awk '{print $2}' `
  
  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
nohup java -Xms128m -Xmx512m -jar $JAR_PATH/$JAR_NAME --spring.profiles.active=212 >> null 2>&1 &
    echo ">>> start $APP_NAME successed PID=$! <<<"
   fi
  }
 

stop(){
  is_exist
  if [ $? -eq "0" ]; then
    echo ">>> PID = $pid begin kill -9 $pid  <<<"
    kill -9  $pid
    sleep 2
    echo ">>> $APP_NAME process stopped <<<" 
  else
    echo ">>> $APP_NAME is not running <<<"
  fi 
}
 

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
}
 
printLog()
{
tail -f /home/ap/zhfc/t_jar/okdata/logs/session/session_debug.log
}

case "$1" in
  "start")
    start
    printLog
    ;;
  "stop")
    stop
    ;;
  "status")
    status
    ;;
  "restart")
    restart
    printLog
    ;;
  *)
    usage
    ;;
esac
exit 0
 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/139809
推荐阅读
相关标签
  

闽ICP备14008679号