linux自动kill进程自动启动jar包脚本

linux自动kill进程自动启动jar包脚本

绿林寻猫
2022-03-11 / 0 评论 / 603 阅读 / 正在检测是否收录...

start.sh

#!/bin/bash
NAME="xx.jar"    #想要杀死的进程
PORT="8888" #端口
PROCESS="xx.jar" #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..."
    tail -f nohup.out
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..."
    tail -f nohup.out
fi

0

评论 (0)

取消