def chg_iptable(self, wars_with_md5, confs_with_md5): if not self.__run1() and not self.__run2(): return False, "Nothing running cann't chg" if IptableWrap.is_iptables_tom2(): if not self.__run1(): return False, "current iptables is tom2, but tom1 is not running, cann't chg" if self.tomcat1.check_md5(wars_with_md5, confs_with_md5): log_util.info("[start] chg iptable for tom8080") result = util.run_cmd( "iptables -t nat -D PREROUTING -p tcp --dport 8080 -j REDIRECT --to-ports 8180" ) if result["code"] > 0: return False, result["info"][1] self.__kill2() else: return False, "check tom1's md5 fail, cann't chg" else: if not self.__run2(): return False, "current iptables is tom1, but tom2 is not running, cann't chg" if self.tomcat2.check_md5(wars_with_md5, confs_with_md5): log_util.info("[start] chg iptable for tom8180") result = util.run_cmd( "iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-ports 8180" ) if result["code"] > 0: return False, result["info"][1] self.__kill1() else: return False, "check tom2's md5 fail, cann't chg" return True, "success"
def __remove_work(self): log_util.debug("start to remove work dir") result = util.run_cmd("rm -rf %swork/Catalina" % self.tomcat_path) if result["code"] > 0: log_util.error(result["info"][1]) return False return True
def __remove_unpack(self, wars_with_md5): for war_path in wars_with_md5.keys(): war_name = util.get_file_name(war_path) war_pre_name = war_name[:-4] log_util.debug("start to remove war: %s", war_name) result = util.run_cmd("rm -rf %swebapps/%s" % (self.tomcat_path, war_name)) if result["code"] > 0: log_util.error(result["info"][1]) return False log_util.debug("start to remove war dir: %s", war_pre_name) result = util.run_cmd("rm -rf %swebapps/%s" % (self.tomcat_path, war_pre_name)) if result["code"] > 0: log_util.error(result["info"][1]) return False return True
def check_run(self): if self.__run_pid != "": pid_cmd = "ps -p '%s' >/dev/null 2>&1; echo $?" % self.__run_pid result = util.run_cmd(pid_cmd) if result["code"] > 0 or result["info"][0].replace("\n", "") == "0": return True return False
def is_iptables_tom2(): log_util.info("check iptables") result = util.run_cmd("iptables-save") iptables_info = result["info"][0] if result["code"] > 0: raise Exception("run iptables-save error") return re.search( "-A PREROUTING -p tcp -m tcp --dport 8080 -j REDIRECT --to-ports 8180", iptables_info)
def get_script_info(): """ :return: is_script_run, script_pid """ if not os.path.exists(conf.SCRIPT__PID_FILE_PATH): return False, "" file_object = open(conf.SCRIPT__PID_FILE_PATH) try: pid = file_object.read() finally: file_object.close() pid_cmd = "ps -p '%s' >/dev/null 2>&1; echo $?" % pid result = util.run_cmd(pid_cmd) if result["code"] > 0: raise Exception("Check pid exist error: %s" % pid) if result["info"][0].replace("\n", "") == "0": return True, pid return False, pid
def get_pid(self): return (util.run_cmd("cat %stomcat.pid" % self.tomcat_path)["info"][0]).replace("\n", "")
def __start_tomcat(self): result = util.run_cmd("/bin/sh %sbin/startup.sh" % self.tomcat_path) if result["code"] > 0: log_util.error("%s, %s" % (result["info"][0], result["info"][1])) return False return True