nacos批量启动、查看状态、关闭脚本

一、直接给代码

1. start.sh

  • 使用方法
[root@localhost] #ls
nacos
./start.sh ./nacos -m standalone # 单机模式
./start.sh ./nacos -m cluster # 集群模式
  • 代码
#!/bin/bash

function read_dir() {
  for file in `ls $1`
  do
    if [[ -d $1"/"$file ]];
      then
        read_dir $1"/"$file $2 $3
    else
      if [[ -f $1"/"$file ]] && [[ "$file" = startup.sh ]];
        then
          cd ./$1
          if [[ "$2" = "-m" ]];
	    then
	      if [[ "$3" = "standalone" ]];
	        then
	          ./startup.sh -m standalone > /dev/null
	          echo $1$file 单机模式启动成功!
		  cd - > /dev/null
	      elif [[ "$3" = "cluster" ]];
	        then
	          ./startup.sh -m cluster > /dev/null
 	          echo $1$file 集群模式启动成功!
		  cd - > /dev/null
	      else
	        echo "1adUsage: ./startup.sh [Directory] -m [standalone | cluster]"
	      fi
	  else
	    echo "2Usage: ./startup.sh [Directory] -m [standalone | cluster]"
	    exit -1;
          fi
      fi
    fi
  done
}

# 读取第一个参数
read_dir $1 $2 $3


2. status.sh

  • 使用方法
[root@localhost] #ls
nacos
./status.sh ./nacos -m standalone # 单机模式
./status.sh ./nacos -m cluster # 集群模式
  • 代码
#!/bin/bash

target_dir=$1

if [[ "$target_dir" = "" ]] || [[ ! -d $target_dir ]];
then
  echo "Usage: ./status.sh [Dir]"
fi

pid=`ps ax | grep -i 'nacos.nacos' | grep ${target_dir} | grep java | grep -v grep | awk '{print $1}'`

if [[ -z "$pid" ]];
then
  echo "No NacosServer running."
 exit -1;
fi

echo "The nacosServer $1"nacos-server.jar"  is running, it's pids as follow:"
echo "$pid"




3.stop.sh

  • 使用方法
[root@localhost] #ls
nacos
./status.sh ./nacos -m standalone # 单机模式
./status.sh ./nacos -m cluster # 集群模式
  • 代码
#!/bin/bash

target_dir=$1

pid=`ps ax | grep -i 'nacos.nacos' | grep ${target_dir} | grep java | grep -v grep | awk '{print $1}'`
if [ -z "$pid" ] ; then
        echo "No nacosServer running."
        exit -1;
fi

echo "The nacosServer $1"nacos-server.jar"  is running, it's pids as follow:"
echo  "$pid"

kill ${pid}

echo "Services stop successfully! which has been killed forcibly!"
echo pid as follow: 
echo "$pid"

二、结束语

评论区可留言,可私信,可互相交流学习,共同进步,小生会努力写出优质文章,期待同友多多回访。

专注品质,热爱生活。
交流技术,寻求同志。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嗝屁小孩纸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值