Nacos batch startup, status viewing, shutdown script
Nacos batch startup, status viewing, shutdown script
1. Give the code directly
1.start.sh
- Instructions
[root@localhost] #ls
nacos
./start.sh ./nacos -m standalone # stand-alone mode
./start.sh ./nacos -m cluster # clustering mode
- code
#!/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 Standalone mode started successfully!
cd - > /dev/null
elif [[ "$3" = "cluster" ]];
then
./startup.sh -m cluster > /dev/null
echo $1$file Cluster mode started successfully!
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 the first parameter
read_dir $1 $2 $3

2. status.sh
- Instructions
[root@localhost] #ls
nacos
./status.sh ./nacos -m standalone # stand-alone mode
./status.sh ./nacos -m cluster # clustering mode
- code
#!/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
- Instructions
[root@localhost] #ls
nacos
./status.sh ./nacos -m standalone # stand-alone mode
./status.sh ./nacos -m cluster # clustering mode
- code
#!/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"

2. Conclusion
You can leave messages in the comment area, send private messages, communicate with each other, learn from each other, and make progress together. Xiaosheng will work hard to write high-quality articles, and I look forward to many return visits from my colleagues.
Focus on quality and love life.
Exchange technology and seek comrades.