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)