服务管理脚本

服务启动脚本

project.sh

#!/bin/bash
#filename: project.sh
#function: project start/stop shell


project=proxy-security-0827.jar
filename=project.sh

#使用说明
usage(){
 echo please use ./$filename [start][stop][restart][status]
}

isExist(){
pid=`ps -ef | grep -v grep | grep $project | awk '{print $2}'`
 if [[ -z $pid ]];then
  echo $pid 
  return 1
 else
  echo $pid
  return 0
 fi
}

start(){
  isExist
  if [[ $? -eq 0 ]];then
    echo $project is already started,pid is $pid
  else 
    java -jar $project &
    echo $project is started,please use [./$filename status] view status.
  fi
}

stop(){
  isExist
  if [[ $? -eq 1 ]];then
    echo $project is already stopped.
  else 
    kill -9 $pid
    echo $project is stopped,please use [./$filename status] view status.
  fi
}

restart(){
  stop
  start
}

status(){
 isExist
 if [[ $? -eq 0 ]];then
   echo $project is running.
 else 
   echo $project is stopped.
 fi
}

case $1 in
 start)
  start;;
 stop)
  stop;;
 restart)
  restart;;
 status)
  status;;
 *)
  usage;;
esac

posted @ 2021-09-21 16:15  ynsocool  阅读(38)  评论(0)    收藏  举报