def SvcShutdown(self): if node.__node__['state'] != 'running': return Flag.set(Flag.REBOOT) srv = bus.messaging_service message = srv.new_message(Messages.WIN_HOST_DOWN) srv.get_producer().send(Queues.CONTROL, message)
def on_IntServerHalt(self, message): Flag.set(Flag.HALT) msg = self.new_message(Messages.HOST_DOWN, broadcast=True) try: bus.fire("before_host_down", msg) finally: self.send_message(msg) bus.fire("host_down")
def on_IntServerReboot(self, message): # Scalarizr must detect that it was resumed after reboot Flag.set(Flag.REBOOT) # Send message msg = self.new_message(Messages.REBOOT_START, broadcast=True) try: bus.fire("before_reboot_start", msg) finally: self.send_message(msg) bus.fire("reboot_start")
def SvcShutdown(self): if __node__['state'] != 'running': self._logger.debug( 'Skipping Win_HostDown firing, server state is: {}'.format( __node__['state'])) return Flag.set(Flag.REBOOT) srv = bus.messaging_service message = srv.new_message(Messages.WIN_HOST_DOWN) srv.get_producer().send(Queues.CONTROL, message)
def on_start(self): optparser = bus.optparser """ [SCALARIZR-1564] if iptables.enabled(): iptables.save() """ current_boot_id = get_boot_id() if os.path.exists(self.saved_boot_id_file): with open(self.saved_boot_id_file, 'r') as fp: saved_boot_id = fp.read() if saved_boot_id and saved_boot_id != current_boot_id \ and not Flag.exists(Flag.HALT): self._logger.debug( 'Boot-ID changed (new: {}, saved: {})'.format( current_boot_id, saved_boot_id)) Flag.set(Flag.REBOOT) with open(self.saved_boot_id_file, 'w') as saved_fp: saved_fp.write(current_boot_id) if Flag.exists(Flag.REBOOT) or Flag.exists(Flag.HALT): if Flag.exists(Flag.REBOOT): self._logger.info("Scalarizr resumed after reboot") Flag.clear(Flag.REBOOT) else: self._logger.info( "Scalarizr resumed after server stop (same as reboot)") Flag.clear(Flag.HALT) self._assign_hostname() self._start_after_reboot() elif optparser and optparser.values.import_server: self._logger.info('Server will be imported into Scalr') self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info( 'Server import resumed. Awaiting Rebundle message') elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start") self._assign_hostname()
def shutdown(cls): logger = logging.getLogger(__name__) if __node__['state'] != 'running': logger.debug( 'Skipping Win_HostDown firing, server state is: {}'.format( __node__['state'])) return if Flag.exists(Flag.REBOOT): logger.debug( 'Skipping shutdown routines, cause reboot flag already set' ) return Flag.set(Flag.REBOOT) srv = bus.messaging_service message = srv.new_message(Messages.WIN_HOST_DOWN) srv.get_producer().send(Queues.CONTROL, message)
def on_start(self): if iptables.enabled(): iptables.save() optparser = bus.optparser if os_dist['family'] != 'Windows': if os.path.exists(self.saved_boot_id_file): saved_boot_id = None current_boot_id = None with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'r') as fp: saved_boot_id = fp.read() if saved_boot_id and saved_boot_id != current_boot_id: Flag.set(Flag.REBOOT) with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'w') as saved_fp: saved_fp.write(current_boot_id) if Flag.exists(Flag.REBOOT) or Flag.exists(Flag.HALT): self._logger.info("Scalarizr resumed after reboot") Flag.clear(Flag.REBOOT) Flag.clear(Flag.HALT) self._check_control_ports() self._start_after_reboot() elif optparser and optparser.values.import_server: self._logger.info('Server will be imported into Scalr') self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info( 'Server import resumed. Awaiting Rebundle message') elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start") self._check_control_ports()
def on_start(self): if iptables.enabled(): iptables.save() optparser = bus.optparser if os_dist['family'] != 'Windows': if os.path.exists(self.saved_boot_id_file): saved_boot_id = None current_boot_id = None with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'r') as fp: saved_boot_id = fp.read() if saved_boot_id and saved_boot_id != current_boot_id: Flag.set(Flag.REBOOT) with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'w') as saved_fp: saved_fp.write(current_boot_id) if Flag.exists(Flag.REBOOT) or Flag.exists(Flag.HALT): self._logger.info("Scalarizr resumed after reboot") Flag.clear(Flag.REBOOT) Flag.clear(Flag.HALT) self._check_control_ports() self._start_after_reboot() elif optparser and optparser.values.import_server: self._logger.info('Server will be imported into Scalr') self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info('Server import resumed. Awaiting Rebundle message') elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start") self._check_control_ports()
def handler(*args): Flag.set(Flag.HIR) # FIXME: how about apply all HIR configuration here? self._logger.debug('HIR.body.base: %s', message.body.get('base', {})) __node__['base'].update(message.body.get( 'base', {})) # update node with 'base' settings bus.fire("host_init_response", message) hostup_msg = self.new_message(Messages.HOST_UP, broadcast=True) hostup_msg.body['base'] = { 'hostname': self._system_api.get_hostname() } bus.fire("before_host_up", hostup_msg) if bus.scalr_version >= (2, 2, 3): self.send_message(Messages.BEFORE_HOST_UP, broadcast=True, handle_before_host_up=True) self.send_message(hostup_msg) bus.cnf.state = ScalarizrState.RUNNING bus.fire("host_up")
def _update_package(self): up_script = self._cnf.rawini.get(config.SECT_GENERAL, config.OPT_SCRIPTS_PATH) + "/update" system2([sys.executable, up_script], close_fds=True) Flag.set("update")
def on_start(self): optparser = bus.optparser """ [SCALARIZR-1564] if iptables.enabled(): iptables.save() """ if os_dist['family'] != 'Windows': if os.path.exists(self.saved_boot_id_file): saved_boot_id = None current_boot_id = None with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'r') as fp: saved_boot_id = fp.read() if saved_boot_id and saved_boot_id != current_boot_id \ and not Flag.exists(Flag.HALT): Flag.set(Flag.REBOOT) with open(self.boot_id_file, 'r') as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, 'w') as saved_fp: saved_fp.write(current_boot_id) if Flag.exists(Flag.REBOOT): self._logger.info("Scalarizr resumed after reboot") Flag.clear(Flag.REBOOT) self._check_control_ports() self._start_after_reboot() elif Flag.exists(Flag.HALT): self._logger.info("Scalarizr resumed after server stop") Flag.clear(Flag.HALT) self._check_control_ports() queryenv = bus.queryenv_service farm_role_params = queryenv.list_farm_role_params( farm_role_id=__node__['farm_role_id']) try: resume_strategy = farm_role_params['params']['base'][ 'resume_strategy'] except KeyError: resume_strategy = 'reboot' if resume_strategy == 'reboot': self._start_after_reboot() elif resume_strategy == 'init': __node__['state'] = ScalarizrState.BOOTSTRAPPING self._logger.info( 'Scalarizr will re-initialize server due to resume strategy' ) self._start_init() elif optparser and optparser.values.import_server: self._logger.info('Server will be imported into Scalr') self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info( 'Server import resumed. Awaiting Rebundle message') elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start") self._check_control_ports()
def on_start(self): optparser = bus.optparser """ [SCALARIZR-1564] if iptables.enabled(): iptables.save() """ if os_dist["family"] != "Windows": if os.path.exists(self.saved_boot_id_file): saved_boot_id = None current_boot_id = None with open(self.boot_id_file, "r") as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, "r") as fp: saved_boot_id = fp.read() if saved_boot_id and saved_boot_id != current_boot_id and not Flag.exists(Flag.HALT): Flag.set(Flag.REBOOT) with open(self.boot_id_file, "r") as fp: current_boot_id = fp.read() with open(self.saved_boot_id_file, "w") as saved_fp: saved_fp.write(current_boot_id) if Flag.exists(Flag.REBOOT): self._logger.info("Scalarizr resumed after reboot") Flag.clear(Flag.REBOOT) self._check_control_ports() self._start_after_reboot() elif Flag.exists(Flag.HALT): self._logger.info("Scalarizr resumed after server stop") Flag.clear(Flag.HALT) self._check_control_ports() queryenv = bus.queryenv_service farm_role_params = queryenv.list_farm_role_params(farm_role_id=__node__["farm_role_id"]) try: resume_strategy = farm_role_params["params"]["base"]["resume_strategy"] except KeyError: resume_strategy = "reboot" if resume_strategy == "reboot": self._start_after_reboot() elif resume_strategy == "init": __node__["state"] = ScalarizrState.BOOTSTRAPPING self._logger.info("Scalarizr will re-initialize server due to resume strategy") self._start_init() elif optparser and optparser.values.import_server: self._logger.info("Server will be imported into Scalr") self._start_import() elif self._cnf.state == ScalarizrState.IMPORTING: self._logger.info("Server import resumed. Awaiting Rebundle message") elif self._cnf.state == ScalarizrState.BOOTSTRAPPING: self._logger.info("Starting initialization") self._start_init() else: self._logger.info("Normal start") self._check_control_ports()
def _update_package(self): up_script = self._cnf.rawini.get(config.SECT_GENERAL, config.OPT_SCRIPTS_PATH) + '/update' system2([sys.executable, up_script], close_fds=True) Flag.set('update')
def SvcShutdown(self): Flag.set(Flag.REBOOT) srv = bus.messaging_service message = srv.new_message(Messages.WIN_HOST_DOWN) srv.get_producer().send(Queues.CONTROL, message)