mungerz

解决问题:

Linux Shell脚本 实现发现进程,杀死进程,重启进程

 

实现代码:

#!/bin/bash
NAME="provider-integral"    #想要杀死的进程
PORT="8081"
PROCESS="../jars/provider-integral-0.0.1-SNAPSHOT.jar"
LOGDIR="../log/integral.log"
echo $NAME
ID=`ps -ef | grep "$NAME" | grep -v "grep" | awk \'{print $2}\'`  #注意此shell脚本的名称,避免自杀
if [ -z "$ID" ];then
    echo "process id is empty, process is not existed..."
    echo "process will start..."
    nohup java -Dserver.port=$PORT -jar $PROCESS  > $LOGDIR 2>&1 &
    echo "process has start..."
else
    echo $ID
        for id in $ID
        do
        kill -9 $id
        echo "killed $id"
    done
    echo "process will restart..."
    nohup java -Dserver.port=$PORT -jar $PROCESS  > $LOGDIR 2>&1 &
    echo "process has restart..."
fi

 

转载请标明出处

分类:

技术点:

相关文章:

  • 2021-06-23
  • 2022-01-21
  • 2021-11-22
  • 2022-12-23
  • 2021-09-02
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-10
  • 2021-12-15
相关资源
相似解决方案