Linux Shell脚本 实现发现进程,杀死进程,重启进程
解决问题:
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
转载请标明出处