diff --git a/scripts/publish_cpp_i_n/boundle.sh b/scripts/publish_cpp_i_n/boundle.sh new file mode 100644 index 0000000..a8801b5 --- /dev/null +++ b/scripts/publish_cpp_i_n/boundle.sh @@ -0,0 +1,16 @@ +source ./common.sh + +cd ${SOURCE_PATH} +${PRE_COMPILE_CMD} +cmake ${COMPILE_FLAGS} +make clean +make +cp ../bin/${SRC_EXE_NAME} ../../../../bin/${PROJECT_NAME} + +cd ../../../../ + +tag_name=`git status |grep '# On branch '|sed 's/# On branch //g'` +dir_name=`basename $PWD` +package_name=${dir_name}.tar.gz + +tar --exclude=*.git -chzf target/${package_name} bin common.sh reload.sh restart.sh start_instance.sh manage.py config diff --git a/scripts/publish_cpp_i_n/manage.py b/scripts/publish_cpp_i_n/manage.py new file mode 100755 index 0000000..af4f6e3 --- /dev/null +++ b/scripts/publish_cpp_i_n/manage.py @@ -0,0 +1,73 @@ +#!/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, progname): + pids = getRuningProgramPids(progname) + for pid in pids: + exepath = getExePath(pid) + cmdline = getExeCmdLine(pid) + if cmdline == ("./%s\0-i\0%d\0-n\0%d\0" % (progname, instance_id, node_id)): + os.popen('kill -9 %d' % int(pid)) + +def listServer(progname): + pids = getRuningProgramPids(progname) + for pid in pids: + exepath = getExePath(pid) + cmdline = getExeCmdLine(pid) + print(pid, exepath, cmdline) + +def restartServer(str_instance_ids, str_node_id, progname): + 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, progname) + time.sleep(0.5) + print('%s %d %d starting......' % (progname, instance_id, node_id)) + cmd = 'sh start_instance.sh %d %d' % (instance_id, node_id) + os.popen(cmd) + time.sleep(0.5) + +def printHelp(): + print('usuage: [restart stop list]') + +def main(argv): + if len(argv) == 1: + printHelp() + else: + if argv[1] == 'restart': + restartServer(argv[2], argv[3], argv[4]) + elif argv[1] == 'stop': + stop(argv[2], argv[3], argv[4]) + elif argv[1] == 'list': + listServer(argv[2]) + +if __name__ == '__main__': + main(sys.argv) diff --git a/scripts/publish_cpp_i_n/reload.sh b/scripts/publish_cpp_i_n/reload.sh new file mode 100644 index 0000000..38c7f0e --- /dev/null +++ b/scripts/publish_cpp_i_n/reload.sh @@ -0,0 +1,2 @@ +source ./common.sh +echo ${COMPILE_FLAGS} diff --git a/scripts/publish_cpp_i_n/restart.sh b/scripts/publish_cpp_i_n/restart.sh new file mode 100755 index 0000000..18a7f93 --- /dev/null +++ b/scripts/publish_cpp_i_n/restart.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +source ./common.sh + +python manage.py restart $1 $2 ${PROJECT_NAME} + +echo 'success' diff --git a/scripts/publish_cpp_i_n/start_instance.sh b/scripts/publish_cpp_i_n/start_instance.sh new file mode 100755 index 0000000..125ded7 --- /dev/null +++ b/scripts/publish_cpp_i_n/start_instance.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +source ./common.sh + +cd bin +nohup ./${PROJECT_NAME} -i $1 -n $2 >> ${PROJECT_NAME}$2_$1.out 2>&1 &