服务停止启动-脚本

发布于 2019-03-30  463 次阅读


因公司一次停电,服务需要停止服务器,写下的脚本。笔记。。

关闭redis


#!/bin/bash
function stop_redis () {
ps aux | grep redis | grep $1 | awk '{print $2}' | xargs kill
}

stop_redis 6381
stop_redis 6379
stop_redis 6340
stop_redis 6380
stop_redis 6341
stop_redis 6392
stop_redis 6389
stop_redis 6342
stop_redis 4010
stop_redis 4011
stop_redis 4012
stop_redis 4013
stop_redis 4014
stop_redis 4015
stop_redis 4016
stop_redis 4017
stop_redis 4018
stop_redis 4019
stop_redis 4020
stop_redis 4000
stop_redis 4001
stop_redis 4002
stop_redis 4003
stop_redis 4004
stop_redis 4005
stop_redis 4006
stop_redis 4007
stop_redis 4008
stop_redis 4009
stop_redis 4021
stop_redis 4022
stop_redis 4023
stop_redis 4024
stop_redis 4025
stop_redis 4026
stop_redis 4027
stop_redis 4028
stop_redis 4029

启动redis
第一种 有序批量

#!/bin/bash
for port in {23..25}
do
redis-server --daemonize yes --port 40${port}
done

第二种 无序,指定端口

#!/bin/bash
for port in 6340 6380 6341 6342
do
redis-server --daemonize yes --port $port
done

第三种 无序,指定端口

export PATH=/usr/local/bin:$PATH
R="6898 6379"
for i in $R; do
echo $i;
redis-server --port $i --daemonize yes
done

关闭gateway

#!/bin/bash
function stop_gateway() {
cd $1 && ./ops/stopall;
}
stop_gateway /home/xxxx/branch/20190121_week_release_6
stop_gateway /home/xxxx/trunk/server_1004
stop_gateway /home/xxxx/server
stop_gateway /home/xxxx/server_backup_20180610
stop_gateway /home/xxxx/branch/common_dev_0806
stop_gateway /home/xxxx/branch/20190121_week_release_5
stop_gateway /home/xxxx/branch/20190121_week_release_7

启动gateway

#!/bin/bash
function start_gateway() {
cd $1 && ./ops/restartall;
}
start_gateway /home/xxxx/branch/20190121_week_release_6
start_gateway /home/xxxx/trunk/server_1004
start_gateway /home/xxxx/server
start_gateway /home/xxxx/server_backup_20180610
start_gateway /home/xxxx/branch/common_dev_0806
start_gateway /home/xxxx/branch/20190121_week_release_5
start_gateway /home/xxxx/branch/20190121_week_release_7

关闭zookeeper

#!/bin/bash
cd /home/xxxx/work/zookeeper-2.3.0/ && ./zkServer.sh stop

启动zookeeper

#!/bin/bash
cd /home/xxxx/work/zookeeper-2.3.0/ && ./zkServer.sh start

一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。