linux脚本执行kill进程并重启

linux脚本执行kill进程并重启

绿林寻猫
2022-01-15 / 0 评论 / 363 阅读 / 正在检测是否收录...
#!/bin/bash
NAME="***.jar"    #想要杀死的进程
PORT="82" #进程端口
PROCESS="***.jar"
LOGDIR="nohup.out"
echo $NAME
ID=`ps -ef |grep java|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 -Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m $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 -Xms256m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m $PROCESS  > $LOGDIR 2>&1 &
    echo "process has restart..."
fi
0

评论 (0)

取消