miduo_gm/conf/script/deluser.sh

42 lines
1.2 KiB
Bash
Raw Normal View History

2023-07-26 17:30:12 +08:00
#!/bin/bash
2023-08-10 16:33:36 +08:00
# 参数处理
gameip=$1 # IP地址
serverid=$2 # 服务器ID
proccessname=$3 # 进程名称
mongourl=$4 # MongoDB地址
redisIp=$5 # Redis IP
redisPwd=$6 # Redis 密码
2023-07-26 17:30:12 +08:00
2023-08-10 16:33:36 +08:00
# 停止游戏进程
ansible "$gameip" -m shell -a "supervisorctl stop $proccessname"
if [ $? -ne 0 ]; then
echo "停止游戏进程失败,退出脚本。"
exit 1
fi
2023-07-26 17:30:12 +08:00
2023-08-10 16:33:36 +08:00
# 清除MongoDB数据
tempFile="/data/jieling/gm/config/script/clearMongo.js"
2023-07-26 17:30:12 +08:00
2023-08-10 16:33:36 +08:00
mongo "mongodb://${mongourl}/jieling_${serverid}?authSource=admin" "$tempFile"
if [ $? -ne 0 ]; then
echo "清除MongoDB数据失败退出脚本。"
exit 1
fi
2023-07-26 17:30:12 +08:00
2023-08-10 16:33:36 +08:00
# 删除Redis数据
2023-08-15 18:49:49 +08:00
num=$(redis-cli -h "$redisIp" -a "$redisPwd" keys "${serverid}*"|wc -l)
2023-08-10 16:33:36 +08:00
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数据..."
2023-07-26 17:30:12 +08:00
else
2023-08-10 16:33:36 +08:00
echo "用户数过多,无法删除成功。"
2023-07-26 17:30:12 +08:00
fi
2023-08-10 16:33:36 +08:00
# 启动游戏进程
2023-08-03 15:49:18 +08:00
ansible "$gameip" -m shell -a "supervisorctl start $proccessname"
2023-08-10 16:33:36 +08:00
if [ $? -ne 0 ]; then
echo "启动游戏进程失败,退出脚本。"
exit 1
fi