208 lines
7.1 KiB
Bash
208 lines
7.1 KiB
Bash
#!/bin/bash
|
|
# 开关子游戏服脚本
|
|
function help1() {
|
|
echo "INPUT ServerID "
|
|
echo "FOrExample: $0 200 # 查看200游戏服的进程号"
|
|
echo "FOrExample: $0 200 201 # 查看200和201游戏服的进程号"
|
|
echo
|
|
echo "INPUT close ServerID "
|
|
echo "ForEXamplE: $0 close 200 # 关闭200游戏服"
|
|
echo "ForEXamplE: $0 close 200 201 # 关闭200和201游戏服的进程号"
|
|
echo "INPUT open ServerID"
|
|
echo "FORexample: $0 open 200 # 打开200游戏服"
|
|
echo "FORexample: $0 open 200 201 # 打开200和201游戏服"
|
|
echo
|
|
echo "INPUT check "
|
|
echo "ForEXAMple: $0 check # 查看所有游戏进程"
|
|
echo
|
|
echo "INPUT list "
|
|
echo "FOREMamplE: $0 list # 查看游戏对应游戏列表"
|
|
exit
|
|
}
|
|
function send_record(){
|
|
python3 /root/disk2/200Gdisk/mysqlBackup/record.py "新加坡正式服" "$0" "正在使用开关服脚本" "$1" "$2" "$3"
|
|
}
|
|
GAMEPATH="/root/disk2/trunk/Run/"
|
|
GAMEFILE="$GAMEPATH/GameService"
|
|
username="finduser"
|
|
password=""
|
|
hostname="172.30.250.36"
|
|
port=33060
|
|
record=0
|
|
[ ! -f $GAMEFILE ] && echo "PATH NOT EXIST: $GAMEPATH" && exit
|
|
# 需要一个仅有ID,Name只读字段的用户
|
|
data=$(mysql -h$hostname -u$username -p$password -P 33060 -e "SELECT ID,Name from DJH_PlatformDB.ServerInfo")
|
|
[ $? -ne 0 ] && echo "DATABASE CONNECT ERROR" && exit
|
|
floatage=0
|
|
deal=""
|
|
for i in $(echo $data); do
|
|
let floatage=$floatage+1
|
|
if [ $floatage -le 2 ]; then # 前面2个为查询字段
|
|
continue
|
|
fi
|
|
if [ $(($floatage % 2)) -eq 0 ]; then # 偶数为 服务器ID
|
|
deal="$deal $i\n"
|
|
else
|
|
deal="$deal$i"
|
|
fi
|
|
done
|
|
|
|
case $# in
|
|
0)
|
|
help1
|
|
;;
|
|
1)
|
|
[ "$1" == "close" ] && help1
|
|
[ "$1" == "open" ] && help1
|
|
if [ "$1" == "check" ]; then
|
|
ps -aux | grep GameService
|
|
elif [ "$1" == "list" ]; then
|
|
echo -e $deal
|
|
else
|
|
ps -aux | grep "GameService" | grep -w "GameService $1" | grep -v "grep"
|
|
ps -aux | grep "GameService" | grep -w "GameService $1" | grep -v "grep" | awk '{print $2}'
|
|
fi
|
|
;;
|
|
2)
|
|
if [ "$1" == "close" ]; then
|
|
cd $GAMEPATH
|
|
ps -aux | grep "GameService" | grep -w "GameService $2" | grep -v "grep"
|
|
[ $? -ne 0 ] && echo "SERVERID NOT RUNNING" && exit
|
|
SPPID=$(ps -aux | grep "GameService" | grep -w "GameService $2" | grep -v "grep" | awk '{print $2}')
|
|
echo -e $deal | grep -Ew $2 | awk 'NR<'$#'{print $1" => "$2}'
|
|
echo $SPPID
|
|
read -p "close All? y/n: " confirm
|
|
if [ "$confirm" == "y" ] || [ "$confirm" == "Y" ]; then
|
|
./GameService close $SPPID
|
|
[ $record -eq 1 ] && send_record "正在关服" "$temp_message"
|
|
else
|
|
exit
|
|
fi
|
|
elif [ "$1" == "open" ]; then
|
|
cd $GAMEPATH
|
|
ps -aux | grep -v "grep" | grep -w "GameService $2"
|
|
[ $? -eq 0 ] && echo "ServerID IS RUNNING !" && exit
|
|
echo -e $deal | grep -w "$2" &>/dev/null
|
|
[ $? -ne 0 ] && echo "Not Fount ServerID: $2" && exit
|
|
echo "open server:"
|
|
echo -e $deal | grep -w $2 | awk '{print $1" => "$2}'
|
|
read -p "open this? y/n: " confirm
|
|
[ "$confirm" != "y" -a "$confirm" != "Y" ] && exit
|
|
./GameService $2 >>./COSDNA.pid
|
|
ps -aux | grep -v "grep" | grep "GameService $2"
|
|
[ $record -eq 1 ] && send_record "正在开服" "$temp_message"
|
|
else
|
|
temp=""
|
|
floatage=0
|
|
for i in $@; do
|
|
let floatage=$floatage+1
|
|
if [ "$temp" != "" ]; then
|
|
temp="$temp|GameService $i"
|
|
else
|
|
temp="GameService $i"
|
|
fi
|
|
done
|
|
ps -aux | grep GameService | grep -w -E "$temp" | grep -v "grep"
|
|
[ $? -ne 0 ] && exit
|
|
ps -aux | grep GameService | grep -w -E "$temp" | grep -v "grep" | awk '{print $2}'
|
|
fi
|
|
;;
|
|
*)
|
|
cd $GAMEPATH
|
|
if [ "$1" == "close" ]; then
|
|
floatage=0
|
|
server_find_string=""
|
|
temp=""
|
|
for i in $@; do
|
|
let floatage=$floatage+1
|
|
if [ $floatage -le 1 ]; then
|
|
continue
|
|
else
|
|
if [ "$temp" != "" ]; then
|
|
temp="$temp|GameService $i"
|
|
else
|
|
temp="GameService $i"
|
|
fi
|
|
server_find_string="$server_find_string|$i"
|
|
fi
|
|
done
|
|
ps -aux | grep GameService | grep -w -E "$temp" | grep -v "grep"
|
|
[ $? -ne 0 ] && exit
|
|
SSPID=$(ps -aux | grep GameService | grep -w -E "$temp" | grep -v "grep" | awk '{print $2}')
|
|
echo "close server:"
|
|
echo -e $deal | grep -Ew $server_find_string | awk 'NR<'$#'{print $1" => "$2}'
|
|
echo $SSPID
|
|
read -p "close All? y/n: " confirm
|
|
if [ "$confirm" == "y" ] || [ "$confirm" == "Y" ]; then
|
|
for i in $SSPID; do
|
|
./GameService close $i
|
|
done
|
|
temp_message=`echo -e $deal | grep -Ew $server_find_string | awk 'NR<'$#'{print $1" => "$2}'`
|
|
[ $record -eq 1 ] && send_record "正在批量关服" "$temp_message"
|
|
else
|
|
exit
|
|
fi
|
|
elif [ "$1" == "open" ]; then
|
|
floatage=0
|
|
server_find_string=""
|
|
temp=""
|
|
for i in $@; do
|
|
let floatage=$floatage+1
|
|
if [ $floatage -le 1 ]; then
|
|
continue
|
|
else
|
|
if [ "$temp" != "" ]; then
|
|
temp="$temp|GameService $i"
|
|
else
|
|
temp="GameService $i"
|
|
fi
|
|
server_find_string="$server_find_string|$i"
|
|
fi
|
|
done
|
|
echo "open server:"
|
|
echo -e $deal | grep -Ew $server_find_string | awk 'NR<'$#'{print $1" => "$2}'
|
|
read -p "open this? y/n: " confirm
|
|
[ "$confirm" != "y" -a "$confirm" != "Y" ] && exit
|
|
floatage=0
|
|
serverid_skip=""
|
|
for i in $@; do
|
|
let floatage=$floatage+1
|
|
if [ $floatage -le 1 ]; then
|
|
continue
|
|
else
|
|
ps -aux | grep -v "grep" | grep -w "GameService $i"
|
|
if [ $? -eq 0 ]; then
|
|
serverid_skip="$serverid_skip $i"
|
|
continue
|
|
else
|
|
./GameService $i >>./COSDNA.pid
|
|
fi
|
|
fi
|
|
done
|
|
if [ "$serverid_skip" != "" ]; then
|
|
echo "open skip serverid: "
|
|
echo "$serverid_skip"
|
|
echo "ServerID is EXIST"
|
|
fi
|
|
ps -aux | grep GameService | grep -w -E "$temp" | grep -v "grep"
|
|
temp_message=`echo -e $deal | grep -Ew $server_find_string | awk 'NR<'$#'{print $1" => "$2}'`
|
|
skip_message="skip serverid: $serverid_skip"
|
|
[ $record -eq 1 ] && send_record "正在批量开服" "$temp_message" "$skip_message"
|
|
else
|
|
temp=""
|
|
floatage=0
|
|
for i in $@; do
|
|
let floatage=$floatage+1
|
|
if [ "$temp" != "" ]; then
|
|
temp="$temp|GameService $i"
|
|
else
|
|
temp="GameService $i"
|
|
fi
|
|
done
|
|
ps -aux | grep GameService | grep -w -E "$temp" | grep -v "grep"
|
|
[ $? -ne 0 ] && exit
|
|
ps -aux | grep GameService | grep -w -E "$temp" | grep -v "grep" | awk '{print $2}'
|
|
fi
|
|
;;
|
|
esac
|