Jar文件挂掉自动重启

Shell脚本:fileRestart.sh

@注:此文件放到jar文件的同级目录:

脚本内容:

#kconfig: - 95 15    

# description: 抓取程序  start/stop/status script 

#JDk 所在的路径  

#export JAVA_HOME=/home/java/jdk1.8.0_60 

#Add Java binary files to PATH   

#export PATH=$JAVA_HOME/bin:$PATH   

 

#需要启动的Java主程序(main方法类)   

PROGRAM_NAME="com.qianmi.controller.FileVerticle.Main"

 

#USAGE is the message if this script is called without any options   

USAGE="Usage: $0 {start,stop,status,restart}"   

 

#SHUTDOWN_WAIT is wait time in seconds for java proccess to stop   

SHUTDOWN_WAIT=20   

#获取执行id 

tomcat_pid() {

        echo `ps -ef | grep $PROGRAM_NAME | grep -v grep | tr -s " "|cut -d" " -f2  ` 

}   

 

##启动 

start() {   

  pid=$(tomcat_pid)   

  if [ -n "$pid" ];then   

    echo -e "spider is already running (pid: $pid)" 

  else   

echo -e "Starting spider"   

#要启动的jar文件filesystem.jar

    nohup java -Dfile.encoding=UTF-8 -classpath "./filesystem.jar:." com.qianmi.controller.FileVerticle.Main  > /dev/null 2>&1  &  status   

  fi   

  return 0   

}   

############## 

#状态 

####### 

status(){

  pid=$(tomcat_pid)   

  if [ -n "$pid" ];then   

    echo -e "spider is running with pid: $pid"   

  else   

    echo -e "spider  is not running"   

  fi   

}   

##停止 

stop() {   

  pid=$(tomcat_pid)   

  if [ -n "$pid" ];then   

    echo -e "Stoping spider"   

    #  shutdown.sh   

    #let kwait=$SHUTDOWN_WAIT  count=0;   

    #until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]   

    #do   

    #  echo -n -e "waiting for processes to exit";   

    #  sleep 1   

    #  let count=$count+1;   

    #done   

 

    if [ $count -gt $kwait ];then   

      echo -n -e "killing processes which didn't stop after $SHUTDOWN_WAIT seconds"   

      kill -9 $pid   

    fi   

  else   

    echo -e "spider  is not running"   

  fi     

  return 0   

}   

user_exists(){   

  if id -u $1 >/dev/null 2>&1; then   

    echo "1"   

  else   

    echo "0"   

  fi   

}   

 

case $1 in   

        start)   

          start   

        ;;   

        stop)     

          stop   

        ;;   

        restart)   

          stop   

          start   

        ;;   

        status)   

      status   

        ;;   

        *)   

      echo -e $USAGE   

        ;;   

esac       

exit 0  

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值