generated from root/miduo_server
gm脚本优化
parent
fefa8d2be3
commit
eb5943bbbc
|
@ -1,48 +1,42 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#set 200 81.71.33.247 20002 "core2"
|
|
||||||
gameip=$1 #ip
|
|
||||||
serverid=$2 #服务器id
|
|
||||||
proccessname=$3 #corename
|
|
||||||
mongourl=$4 #mongo地址
|
|
||||||
redisIp=$5 #redis ip
|
|
||||||
redisPwd=$6 #redis 密码
|
|
||||||
echo $gameip $serverid $proccessname
|
|
||||||
|
|
||||||
#停游戏进程
|
# 参数处理
|
||||||
ansible $gameip -m shell -a "supervisorctl stop $proccessname"
|
gameip=$1 # IP地址
|
||||||
|
serverid=$2 # 服务器ID
|
||||||
|
proccessname=$3 # 进程名称
|
||||||
|
mongourl=$4 # MongoDB地址
|
||||||
|
redisIp=$5 # Redis IP
|
||||||
|
redisPwd=$6 # Redis 密码
|
||||||
|
|
||||||
#删mongo数据
|
# 停止游戏进程
|
||||||
tempFile="/data/jieling/gm/config/script/clearMongo.js"
|
ansible "$gameip" -m shell -a "supervisorctl stop $proccessname"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
#if [ ! -f "$tempFile" ]; then
|
echo "停止游戏进程失败,退出脚本。"
|
||||||
# touch $tempFile
|
exit 1
|
||||||
# echo "print('========= 进入mongo脚本 mongoDB... ==========');" >> $tempFile
|
|
||||||
# echo "if (db.getCollection('user').count()<50){" >> $tempFile
|
|
||||||
# echo "db.getCollection('user').drop();" >> $tempFile
|
|
||||||
# echo "db.getCollection('globalSystemControl').drop();" >> $tempFile
|
|
||||||
# echo "db.getCollection('itemLog').drop();" >> $tempFile
|
|
||||||
# echo "db.getCollection('mailingSystem').drop(); " >> $tempFile
|
|
||||||
# echo "db.getCollection('server_config').drop();" >> $tempFile
|
|
||||||
# echo "db.getCollection('guildInfo').drop();" >> $tempFile
|
|
||||||
# echo "db.getCollection('guildLog').drop(); " >> $tempFile
|
|
||||||
# echo "print('========= mongoDB脚本删除成功... ==========');}" >> $tempFile
|
|
||||||
#fi
|
|
||||||
|
|
||||||
mongo "mongodb://""${mongourl}""/jieling_""${serverid}""?authSource=admin" $tempFile
|
|
||||||
|
|
||||||
#删除redis数据
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
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 "deleting redis data"
|
|
||||||
else
|
|
||||||
echo "too many users,can not delete success"
|
|
||||||
fi
|
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}*")
|
||||||
|
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"
|
ansible "$gameip" -m shell -a "supervisorctl start $proccessname"
|
||||||
#ansible 129.226.193.174 -m shell -a "/data/jieling/bin/start-all.sh core1"
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "启动游戏进程失败,退出脚本。"
|
||||||
|
exit 1
|
||||||
|
fi
|
Loading…
Reference in New Issue