服务启停脚本

2019-05-06  本文已影响0人  叫我宫城大人
jar_name="husky-starter-0.0.1-SNAPSHOT.jar"
log_name="husky.log"

start() {
  echo "service start..."
  nohup java -jar -Dloader.path=./libs $jar_name >./$log_name 2>&1 &
}

stop() {
  echo "service stop..."
  pid=`getPid`
  kill $pid
}

restart() {
  stop
  start
}

getPid() {
  pid=`ps -ef|grep $jar_name|grep -v grep|awk '{printf $2}'`
  echo $pid
}

status() {
  pid=`getPid`
  if [ "$pid" == "" ]; then
    echo "service is stopped"
  else
    echo "service is starting, pid is $pid"
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  status)
    status
    ;;
  *)
    echo "start | stop | restart | status"
    ;;
esac

上一篇下一篇

猜你喜欢

热点阅读