From 57fe3fe6de67c18a681206ff2c78a8098a026e9c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 16 Dec 2019 15:04:31 +0800 Subject: [PATCH] 1 --- server/bin/monitor_masterserver.py | 34 ++++++++++++++++++++++++++++++ server/masterserver/CMakeLists.txt | 8 +++---- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 server/bin/monitor_masterserver.py diff --git a/server/bin/monitor_masterserver.py b/server/bin/monitor_masterserver.py new file mode 100644 index 0000000..6e58304 --- /dev/null +++ b/server/bin/monitor_masterserver.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +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 monitor_ms(gameid): + gameid = gameid.strip(); + if gameid== '': + return + while True: + pids = getRuningProgramPids(f'masterserver{gameid}') + if len(pids) <= 0: + print('zzzz') + os.popen(f'nohup ./masterserver{gameid} -n1 -i1 -f1,2,4 >> masterserver{gameid}.out 2>&1 &') + time.sleep(2) + +monitor_ms(sys.argv[1]) diff --git a/server/masterserver/CMakeLists.txt b/server/masterserver/CMakeLists.txt index f3db6a6..b172687 100644 --- a/server/masterserver/CMakeLists.txt +++ b/server/masterserver/CMakeLists.txt @@ -70,7 +70,7 @@ set(EXECUTABLE_OUTPUT_PATH ) add_executable( - masterserver ${SRC_LIST} + masterserver${GAME_ID} ${SRC_LIST} ) add_custom_target(script_pb_protocol ALL) @@ -78,12 +78,12 @@ add_custom_command(TARGET script_pb_protocol PRE_BUILD COMMAND python ../../third_party/tools/scripts/construct/build_pb.py --cpp_out=. --pb_files=ss_proto,ss_msgid --nohooks 1 ) -add_dependencies(masterserver script_pb_protocol) +add_dependencies(masterserver${GAME_ID} script_pb_protocol) if (CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_libraries( - masterserver + masterserver${GAME_ID} pthread mysqlclient protobuf @@ -101,7 +101,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") ) else() target_link_libraries( - masterserver + masterserver${GAME_ID} pthread mysqlclient protobuf