miduo_gm/conf/script/deluser.sh

42 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/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