脚本包括杀死进程,起动jar包,一步执行(jar包名字自行修改)
#/bin/bash
#clear
lib="";yml="";p1="$1";isNohup=1;ss="debug";
#修改此位置 jar包前缀 yml配置可选
kf="gny-user-center" #前缀
yml=" --spring.config.location=./application-test.yml " #用默认配置 可注释
#以下不需要修改
echo "......";ls -ltr | grep ${kf} | grep -v "grep" | awk '{ print "\033[1;31mb:"$5"\t"$9"\033[0m"}';
if [ -n "$p1" ] ;
then isNohup=0;
fi;
c=0;
for file in `ls -lt ${kf}* | grep .jar | head -n 1 `;
do filelist[$c]=$file;c=`expr $c + 1`;
done;
si=${filelist[4]};
ff="./"${filelist[8]};
si=`expr $si + 1`;
if [[ ${si} -lt 5000000 ]];
then lib=" -Dloader.path=lib ";
fi;
echo "终止进程: ${kf} ps -ef...";
ps -ef | grep ${kf} | grep -v "grep";
echo "正在杀死它...";
pid=$(ps -ef | grep ${kf} | grep -v "grep" | awk '{print $2}');
echo ${pid};for((i=1;i<=5;i++));
do pid=$(ps -ef | grep ${kf} | grep -v "grep" | awk '{print $2}');
if [ -n "$pid" ];
then echo "kill $pid n-${i}";
eval "kill "$pid;sleep 1s;
fi;
done;
pid=$(ps -ef | grep ${kf} | grep -v "grep" | awk '{print $2}');
if [ -n "$pid" ];
then echo "kill -9 $pid must";
eval "kill -9 $pid";sleep 3s;
fi;
pid=$(ps -ef | grep ${kf} | grep -v "grep" | awk '{print $2}');
if [ -n "$pid" ];
then echo "kill -9 $pid must must must !!!";
eval "kill -9 $pid";
sleep 3s;
fi;
pid=$(ps -ef | grep ${kf} | grep -v "grep" | awk '{print $2}');
if [ -n "$pid" ];
then echo "${kf} 我真的杀不掉啊!!!";
exit;
fi;cmd="java -jar ";
if [[ $isNohup == 0 ]];
then
cmd="java -jar "${lib}${ff}${yml}
else
cmd="nohup java -jar "${lib}${ff}${yml}" > ./nohup.out 2>&1 &"
fi
echo "启动... "${cmd};
eval $cmd;