def clean_history_data(): del_old_database = "rm -rf ns.db" try: os.system(del_old_database) ColorPrint.log_high("删除历史数据成功") except BaseException as e: ColorPrint.log_fail('删除历史数据失败: {D}'.format(D=del_old_database)) print e
def start_server(): start_server_cmd = "nohup python ns_server.py &" try: os.system(start_server_cmd) ColorPrint.log_high("启动服务端成功") except BaseException as e: ColorPrint.log_fail('启动服务端失败: {C}'.format(C=start_server_cmd)) raise e
def stop_server(): stop_server_cmd = """ps aux | grep "ns_server.py" | grep -v grep | awk -F " " '{print $2}' | xargs kill -9""" try: os.system(stop_server_cmd) ColorPrint.log_high("停止服务端成功") except BaseException as e: ColorPrint.log_fail('停止服务端失败: %s' % stop_server_cmd) print e
def alert_install_path(): pwd_path = os.getcwd() alert_cmd = """find {PWD} -name "*.sh" | xargs sed -ri 's|INSTALL_PATH=.*|INSTALL_PATH="{INSTALL_PATH_ARGS}"|g'""".format( PWD=pwd_path, INSTALL_PATH_ARGS=apm.install_path) try: os.system(alert_cmd) ColorPrint.log_high("设置安装目录成功: {INSTALL_PATH_ARGS}".format( INSTALL_PATH_ARGS=apm.install_path)) except Exception as e: ColorPrint.log_fail("设置安装目录失败") print e
def start_server(): """ 启动服务端 """ start_server_cmd = "nohup python ns_server.py > log_of_ns_server 2>&1 &" try: os.system(start_server_cmd) ColorPrint.log_high("[+] 启动服务端成功") except BaseException as e: ColorPrint.log_fail('[-] 启动服务端失败: {C}'.format(C=start_server_cmd)) raise e
def clean_history_data(): """ 清理历史数据 """ del_old_database = "rm -rf ns.db" del_old_run_log = "rm -rf log_of_ns_server" try: os.system(del_old_database) os.system(del_old_run_log) ColorPrint.log_high("[+] 删除历史数据成功") except BaseException as e: ColorPrint.log_fail('[-] 删除历史数据失败: {D}'.format(D=del_old_database)) print e
def stop_server(): """ 停止服务端 """ get_pid_server_cmd = """ps aux | grep "ns_server.py" | grep -v grep | awk -F " " '{print $2}'""" try: server_pid_out = os.popen(get_pid_server_cmd).readlines() if len(server_pid_out) == 0: ColorPrint.log_normal("[+] 没有需要停止的服务端") elif len(server_pid_out) == 1: server_pid = server_pid_out[0].strip() kill_server_cmd = "kill -9 %s" % server_pid try: os.system(kill_server_cmd) ColorPrint.log_high("[+] 停止服务端成功") except BaseException as e: ColorPrint.log_fail("[-] 停止服务端失败: %s" % kill_server_cmd) print e except BaseException as e: ColorPrint.log_fail("[-] 获取服务端进程号失败: %s" % get_pid_server_cmd) print e