脚本启动和关闭jar

#! /bin/sh  
PORT=8888  
HOME='/usr/local/java'  
LOG_HOME='/usr/local/java'   
JAR_HOME=auto-weight-0.0.1-SNAPSHOT.jar  
pid=`netstat -apn | grep $PORT | awk '{print $7}' | cut -d/ -f 1`  
stop() {  
 if [ -n "$pid" ];then  
   kill -9 $pid  
   rm -f tpid 
   echo "小程序已成功停止"  
 fi  
}  
  
  
start() {  
 if [ ! -n "$pid" ];then  
  cd $HOME  
  echo "开始启动"  
  nohup java -jar $JAR_HOME&  
  echo $! > tpid   
  echo Start Success! 
 elif [ -n "$pid" ];then 
  echo '小程序正在运行!' 
  exit 
 fi  
}  
case $1 in  
  start)  
    start  
  ;;  
  stop)  
    stop  
  ;;  
  restart)  
   stop  
   start  
  ;;  
  *)  
  echo "请输入正确的命令:stop,start或restart"  
   exit 0  
  ;;  
esac

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页