jdk服务重启脚本

1.nacos+jdk1.8单服务重启脚本

[root@ip-172-31-21-127 auth]# ls
autostart.sh  logs  nohup.out  payment-auth.jar  shutdown.sh  start.sh  startup.sh

[root@ip-172-31-21-127 auth]# cat startup.sh 
#!/bin/bash
bash autostart.sh restart payment-auth.jar & tail -f nohup.out

[root@ip-172-31-21-127 auth]# cat shutdown.sh 
#!/bin/bash
bash autostart.sh stop payment-auth.jar

[root@ip-172-31-21-127 auth]# cat autostart.sh 
#!/bin/bash
source /etc/profile #解决脚本内无法获取到宿主机的java环境
conflocal=/home/payment/config/bootstrap-auth.yml
SpringBoot=$2
BUILD_ID=DONTKILLME
if [ "$1" = "" ];
then
    echo -e "\033[0;31m 未输入操作名 \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"
    exit 1
fi

if [ "$SpringBoot" = "" ];
then
    echo -e "\033[0;31m 未输入应用名 \033[0m"
    exit 1
fi

function start()
{
	count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
	if [ $count != 0 ];then
		echo "$SpringBoot is running..."
	else
		echo "Start $SpringBoot success..."
		nohup java -jar -Xms128M -Xmx512M -XX:TieredStopAtLevel=3 -Dspring.config.location=$conflocal $SpringBoot > nohup.out  &
	fi
}

function stop()
{
	echo "Stop $SpringBoot"
	boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
	count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

	if [ $count != 0 ];then
	    kill $boot_id
    	count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

		boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
		kill -9 $boot_id
	fi
}

function restart()
{
	stop
	sleep 2
	start
}

function status()
{
    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
    if [ $count != 0 ];then
        echo "$SpringBoot is running..."
    else
        echo "$SpringBoot is not running..."
    fi
}

case $1 in
	start)
	start;;
	stop)
	stop;;
	restart)
	restart;;
	status)
	status;;
	*)

	echo -e "\033[0;31m Usage: \033[0m  \033[0;34m sh  $0  {start|stop|restart|status}  {SpringBootJarName} \033[0m
\033[0;31m Example: \033[0m
	  \033[0;33m sh  $0  start esmart-test.jar \033[0m"
esac

2.nacos+jdk1.8多服务同时重启脚本

[root@ip-172-31-21-127 payment]# ls
12051.sql  auth  config  gateway  gen  job  pay  payment  payment.tar  shutdown-all.sh  start-all.sh  system  system-ui

[root@ip-172-31-21-127 payment]# cat start-all.sh 
#!/bin/bash

JAVA_HOME=/home/jdk1.8.0_202

JAR_USER=root

if  [ $USER != $JAR_USER ];then
        echo -e "\n"
        echo -e "\033[5m\033[1m\033[41;33m-------------------Waning!!!-------------------------\033[0m"
        echo "JAR must run at user ($JAR_USER) for security!"
        echo -e "Please run \033[0;31m \"su - devops\" \033[0m first !"
        echo -e "\033[5m\033[1m\033[41;33m-----------------------------------------------------\033[0m"
        echo -e "\n"
     exit 1
fi

for i in  gateway auth system pay
do
    echo $i
    cd $i
    SERVICE_NAME=`ls -t |grep .jar |grep -v pid |head -n1`
    echo $SERVICE_NAME
    SERVICE_DIR=`pwd`
    echo $SERVICE_DIR
    CONFIG=/home/payment/config/bootstrap-${i}.yml
   # CONFIG=/app/happy_lucky/config/bootstrap-${i}.yml
    echo $CONFIG
    P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`
    count=`ps -ef |grep java|grep $SERVICE_NAME|grep -v grep|wc -l`
    if [ $count != 0  ];then
                echo "===$SERVICE_NAME already running, PID is $P_ID ..."
        else
    nohup $JAVA_HOME/bin/java -jar -Xms128M -Xmx512M -XX:TieredStopAtLevel=3 -Dspring.config.location=$CONFIG $SERVICE_NAME >nohup.out &

                 echo "===Start $SERVICE_NAMR success..."

        fi
    cd ..
    sleep 3
    #date
done

[root@ip-172-31-21-127 payment]# cat shutdown-all.sh 
#!/bin/bash

JAVA_HOME=/home/jdk1.8.0_202

for i in  betagent signal system dayend dividend auth gateway
do
    echo $i
    cd $i
    SERVICE_NAME=`ls -t |grep .jar |grep -v pid |head -n1`
    echo $SERVICE_NAME
    SERVICE_DIR=`pwd`
    echo $SERVICE_DIR
    CONFIG=/home/payment/config/bootstrap-${i}.yml
    echo $CONFIG
    P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`
    #count=`ps -ef |grep java|grep $SERVICE_NAME|grep -v grep|wc -l`
    if [ "X$P_ID" = "X" ];then
                echo "===$SERVICE_NAME process not exists or already stop success ..."
        else
                kill -9 $P_ID
                echo "===Stop $SERVICE_NAME (PID $P_ID ) success..."
        fi

    cd ..
    sleep 3
    #date

done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值