From 4d0b3effcade3a463085f27aac28f918d6f7082d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 29 Jun 2019 10:20:46 +0800 Subject: [PATCH] add bin directory --- server/bin/compile.sh | 12 ++++++ server/bin/gmtool.sh | 5 +++ server/bin/manage.py | 75 ++++++++++++++++++++++++++++++++++++ server/bin/monitor.py | 30 +++++++++++++++ server/bin/restart.sh | 5 +++ server/bin/start_instance.sh | 7 ++++ 6 files changed, 134 insertions(+) create mode 100644 server/bin/compile.sh create mode 100755 server/bin/gmtool.sh create mode 100755 server/bin/manage.py create mode 100644 server/bin/monitor.py create mode 100755 server/bin/restart.sh create mode 100755 server/bin/start_instance.sh diff --git a/server/bin/compile.sh b/server/bin/compile.sh new file mode 100644 index 0000000..33b391a --- /dev/null +++ b/server/bin/compile.sh @@ -0,0 +1,12 @@ +cd ../../ +if [ $# == 0 ]; then + git checkout master +else + git checkout $1 +fi +git pull +git submodule init +git submodule update +cd server/gameserver +cmake . +make diff --git a/server/bin/gmtool.sh b/server/bin/gmtool.sh new file mode 100755 index 0000000..faede35 --- /dev/null +++ b/server/bin/gmtool.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd ../tools/robot/virtualclient +#python robot.py ws://192.168.100.21:7101 hao1069 hao1069 $1 +python robot.py "wss://game2001-test.kingsome.cn" hao1069 hao1069 $1 diff --git a/server/bin/manage.py b/server/bin/manage.py new file mode 100755 index 0000000..d86790d --- /dev/null +++ b/server/bin/manage.py @@ -0,0 +1,75 @@ +#!/usr/bin/python +#coding utf8 + +import os +import sys +import time + +def getRuningProgramPids(progname): + pids = [] + lines = os.popen('ps -ef | grep %s' % progname).readlines() + for l in lines: + line = '' + oldc = '' + for c in l.strip(): + if c in [' ', '\t'] and c == oldc: + continue + oldc = c + line += c + line = line.split(' ') + + if line[7] == './%s' % progname: + pids.append(line[1]) + return pids + +def getExePath(pid): + return os.popen('ls -l /proc/%d | grep "exe ->" | cut -d " " -f 7-' % int(pid)).read() + +def getExeCmdLine(pid): + return os.popen('cat /proc/%d/cmdline' % int(pid)).read() + +def stop(instance_id, node_id): + gameserver_ids = getRuningProgramPids('gameserver') + pids = gameserver_ids + for pid in pids: + exepath = getExePath(pid) + cmdline = getExeCmdLine(pid) + if cmdline.find(("./gameserver\0-i\0%d\0-n\0%d\0" % (instance_id, node_id))) > -1: + os.popen('kill -9 %d' % int(pid)) + +def listServer(): + gameserver_ids = getRuningProgramPids('gameserver') + pids = gameserver_ids + for pid in pids: + exepath = getExePath(pid) + cmdline = getExeCmdLine(pid) + print(pid, exepath, cmdline) + +def restartServer(str_instance_ids, str_node_id): + instance_ids = str_instance_ids.split(',') + node_id = int(str_node_id) + for instance_id in instance_ids: + instance_id = int(instance_id) + stop(instance_id, node_id) + time.sleep(0.5) + print('gameserver %d starting......' % instance_id) + cmd = 'sh start_instance.sh %d %d' % (instance_id, node_id) + os.popen(cmd) + time.sleep(0.5) + +def printHelp(): + print('usuage: [restart]') + +def main(argv): + if len(argv) == 1: + printHelp() + else: + if argv[1] == 'restart': + restartServer(argv[2], argv[3]) + elif argv[1] == 'stop': + stop(argv[2], argv[3]) + elif argv[1] == 'list': + listServer() + +if __name__ == '__main__': + main(sys.argv) diff --git a/server/bin/monitor.py b/server/bin/monitor.py new file mode 100644 index 0000000..77a08d3 --- /dev/null +++ b/server/bin/monitor.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +import os +import time + +def getRuningProgramPids(progname): + pids = [] + lines = os.popen('ps -ef | grep %s' % progname).readlines() + for l in lines: + line = '' + oldc = '' + for c in l.strip(): + if c in [' ', '\t'] and c == oldc: + continue + oldc = c + line += c + line = line.split(' ') + + if line[7] == './%s' % progname: + pids.append(line[1]) + return pids + +def monitor_gs(): + while True: + pids = getRuningProgramPids('gameserver2001') + if len(pids) <= 0: + print('zzzz') + os.popen('nohup ./gameserver2001 -n1 -i1 >> gameserver2001.out 2>&1 &') + time.sleep(2) + +monitor_gs() diff --git a/server/bin/restart.sh b/server/bin/restart.sh new file mode 100755 index 0000000..7d3ed21 --- /dev/null +++ b/server/bin/restart.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +python manage.py restart $1 $2 + +echo 'success' diff --git a/server/bin/start_instance.sh b/server/bin/start_instance.sh new file mode 100755 index 0000000..4e7c349 --- /dev/null +++ b/server/bin/start_instance.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +source /etc/profile +source /root/.bash_profile + +nohup ./gameserver -i $1 -n $2 -f1,2,3,4,6>> gameserver$2_$1.out 2>&1 & +