generated from root/miduo_server
42 lines
1.2 KiB
Bash
42 lines
1.2 KiB
Bash
#!/bin/bash
|
||
|
||
# 参数处理
|
||
gameip=$1 # IP地址
|
||
serverid=$2 # 服务器ID
|
||
proccessname=$3 # 进程名称
|
||
mongourl=$4 # MongoDB地址
|
||
redisIp=$5 # Redis IP
|
||
redisPwd=$6 # Redis 密码
|
||
|
||
# 停止游戏进程
|
||
ansible "$gameip" -m shell -a "supervisorctl stop $proccessname"
|
||
if [ $? -ne 0 ]; then
|
||
echo "停止游戏进程失败,退出脚本。"
|
||
exit 1
|
||
fi
|
||
|
||
# 清除MongoDB数据
|
||
tempFile="/data/jieling/gm/config/script/clearMongo.js"
|
||
|
||
mongo "mongodb://${mongourl}/jieling_${serverid}?authSource=admin" "$tempFile"
|
||
if [ $? -ne 0 ]; then
|
||
echo "清除MongoDB数据失败,退出脚本。"
|
||
exit 1
|
||
fi
|
||
|
||
# 删除Redis数据
|
||
num=$(redis-cli -h "$redisIp" -a "$redisPwd" keys "${serverid}*"|wc -l)
|
||
echo "redis数量:$num"
|
||
if [ "$num" -lt 300 ]; then
|
||
redis-cli -h "$redisIp" -a "$redisPwd" keys "${serverid}*" | xargs -r -t -n1 redis-cli -h "$redisIp" -a "$redisPwd" del
|
||
echo "正在删除redis数据..."
|
||
else
|
||
echo "用户数过多,无法删除成功。"
|
||
fi
|
||
|
||
# 启动游戏进程
|
||
ansible "$gameip" -m shell -a "supervisorctl start $proccessname"
|
||
if [ $? -ne 0 ]; then
|
||
echo "启动游戏进程失败,退出脚本。"
|
||
exit 1
|
||
fi |