def _pre_exit(self): """ Method: _pre_exit Description: monitor退出前的处理函数,停止其他进程 Parameter: 无 Return: Others: """ ProcessStatMgr.set_sys_to_stop() for i in xrange(30): if ProcessStatMgr.is_all_process_stoped(): break time.sleep(1) print "." else: ProcessStatMgr.force_stop_all_process() # BasicApp._pre_exit中注销了当前进程的名字服务,导致其他app无法与monitor握手退出 bf.BasicApp._pre_exit(self) if self.__name_manage_worker is not None: self.__name_manage_worker.close_mit_and_name_srv() if self.__cluster_node is not None: self.__cluster_node.stop()
def on_cluster_state_change(self, old_role, old_stats, new_role, new_state, master_ip): # 发送事件 if new_role == cluster.CLUSTER_ROLE_MASTER and old_role != cluster.CLUSTER_ROLE_MASTER: self.__send_cluster_event("event.Cluster.be_master", master_ip) self._name_master_ip = master_ip #print "on_cluster_state_change!!!", master_ip, self.__name_manage_worker if self.__name_manage_worker is not None: self.__name_manage_worker.set_cluster_master_ip(master_ip) self.__name_manage_worker.set_cluster_role(new_role == cluster.CLUSTER_ROLE_MASTER) # 重新注册名字服务 if self.get_my_pid() != bf.INVALID_PID: # 防止正在启动过程中主线程正在注册名字服务 ret = self.regist_name_service() if ret != 0: tracelog.error("regist name service failed when cluster state changed. stop now." "new master:%s" % (master_ip)) self.stop() return if new_role == cluster.CLUSTER_ROLE_MASTER: if new_state == cluster.CLUSTER_STATE_ONLY_MASTER: ProcessStatMgr.set_ha_master(True) else: ProcessStatMgr.set_ha_master(False) else: ProcessStatMgr.set_ha_slave() # 重启所有的进程 ProcessStatMgr.set_sys_to_restart()
def on_master_change(self, old_master_ip, new_master_ip): #print "on_master_change!!!", new_master_ip self._name_master_ip = new_master_ip if self.__name_manage_worker is not None: self.__name_manage_worker.set_cluster_master_ip(new_master_ip) # 重新注册名字服务 if self.get_my_pid() != bf.INVALID_PID: # 防止正在启动过程中主线程正在注册名字服务 ret = self.regist_name_service() if ret != 0: tracelog.error("regist name service failed when master changed. stop now." "new master:%s" % (new_master_ip)) self.stop() return # 重启所有的进程 ProcessStatMgr.set_sys_to_restart()