Example #1
0
def _run_worker():
    LOG.info("(PID=%s) Worker started.", os.getpid())

    action_worker = worker.get_worker()
    _setup_sigterm_handler(action_worker)
    try:
        action_worker.start()
        action_worker.wait()
    except (KeyboardInterrupt, SystemExit):
        LOG.info("(PID=%s) Worker stopped.", os.getpid())

        errors = False

        try:
            deregister_service(service=ACTIONRUNNER)
            action_worker.shutdown()
        except:
            LOG.exception("Unable to shutdown worker.")
            errors = True

        if errors:
            return 1
    except:
        LOG.exception("(PID=%s) Worker unexpectedly stopped.", os.getpid())
        return 1

    return 0
Example #2
0
def _run_worker():
    LOG.info("(PID=%s) TimerEngine started.", os.getpid())

    timer = None

    try:
        timer_thread = None
        if cfg.CONF.timer.enable or cfg.CONF.timersengine.enable:
            local_tz = (cfg.CONF.timer.local_timezone
                        or cfg.CONF.timersengine.local_timezone)
            timer = St2Timer(local_timezone=local_tz)
            timer_thread = concurrency.spawn(_kickoff_timer, timer)
            LOG.info(TIMER_ENABLED_LOG_LINE)
            return timer_thread.wait()
        else:
            LOG.info(TIMER_DISABLED_LOG_LINE)
    except (KeyboardInterrupt, SystemExit):
        LOG.info("(PID=%s) TimerEngine stopped.", os.getpid())
        deregister_service(TIMER_ENGINE)
    except:
        LOG.exception("(PID:%s) TimerEngine quit due to exception.",
                      os.getpid())
        return 1
    finally:
        if timer:
            timer.cleanup()

    return 0
Example #3
0
def main():
    try:
        _setup()

        single_sensor_mode = (cfg.CONF.single_sensor_mode
                              or cfg.CONF.sensorcontainer.single_sensor_mode)

        if single_sensor_mode and not cfg.CONF.sensor_ref:
            raise ValueError(
                "--sensor-ref argument must be provided when running in single "
                "sensor mode")

        sensors_partitioner = get_sensors_partitioner()
        container_manager = SensorContainerManager(
            sensors_partitioner=sensors_partitioner,
            single_sensor_mode=single_sensor_mode,
        )
        return container_manager.run_sensors()
    except SystemExit as exit_code:
        deregister_service(SENSOR_CONTAINER)
        return exit_code
    except SensorNotFoundException as e:
        LOG.exception(e)
        return 1
    except:
        LOG.exception("(PID:%s) SensorContainer quit due to exception.",
                      os.getpid())
        return FAILURE_EXIT_CODE
    finally:
        _teardown()
Example #4
0
    def test_deregister_service_when_service_registry_disables(self):
        service = "api"
        try:
            service_setup.deregister_service(service)
        except:
            assert False, "service_setup.deregister_service raised exception"

        assert True
Example #5
0
File: api.py Project: wingiti/st2
 def queue_shutdown(signal_number, stack_frame):
     deregister_service(STREAM)
     eventlet.spawn_n(
         shutdown_server_kill_pending_requests,
         sock=sock,
         worker_pool=worker_pool,
         wait_time=WSGI_SERVER_REQUEST_SHUTDOWN_TIME,
     )
Example #6
0
def _run_worker():
    LOG.info("(PID=%s) Actions notifier started.", os.getpid())
    actions_notifier = notifier.get_notifier()
    try:
        actions_notifier.start(wait=True)
    except (KeyboardInterrupt, SystemExit):
        LOG.info("(PID=%s) Actions notifier stopped.", os.getpid())
        deregister_service(service=NOTIFIER)
        actions_notifier.shutdown()
    return 0
Example #7
0
File: api.py Project: wingiti/st2
def main():
    try:
        _setup()
        return _run_server()
    except SystemExit as exit_code:
        deregister_service(API)
        sys.exit(exit_code)
    except Exception:
        LOG.exception("(PID=%s) ST2 API quit due to exception.", os.getpid())
        return 1
    finally:
        _teardown()
Example #8
0
 def test_deregister_service_when_service_registry_enabled(self):
     service = "api"
     service_setup.register_service_in_service_registry(service,
                                                        capabilities={
                                                            "hostname": "",
                                                            "pid": ""
                                                        })
     coordinator = coordination.get_coordinator(start_heart=True)
     members = coordinator.get_members(service.encode("utf-8"))
     self.assertEqual(len(list(members.get())), 1)
     service_setup.deregister_service(service)
     self.assertEqual(len(list(members.get())), 0)
Example #9
0
def run_server():
    LOG.info("(PID=%s) Workflow engine started.", os.getpid())

    engine = workflows.get_engine()
    setup_sigterm_handler(engine)
    try:
        engine.start(wait=True)
    except (KeyboardInterrupt, SystemExit):
        LOG.info("(PID=%s) Workflow engine stopped.", os.getpid())
        deregister_service(service=WORKFLOW_ENGINE)
        engine.shutdown()
    except:
        LOG.exception("(PID=%s) Workflow engine unexpectedly stopped.",
                      os.getpid())
        return 1
    return 0
Example #10
0
def _run_worker():
    LOG.info("(PID=%s) RulesEngine started.", os.getpid())

    rules_engine_worker = worker.get_worker()

    try:
        rules_engine_worker.start()
        return rules_engine_worker.wait()
    except (KeyboardInterrupt, SystemExit):
        LOG.info("(PID=%s) RulesEngine stopped.", os.getpid())
        deregister_service(RULESENGINE)
        rules_engine_worker.shutdown()
    except:
        LOG.exception("(PID:%s) RulesEngine quit due to exception.",
                      os.getpid())
        return 1

    return 0
Example #11
0
File: api.py Project: wingiti/st2
def main():
    try:
        _setup()
        return _run_server()
    except SystemExit as exit_code:
        deregister_service(STREAM)
        sys.exit(exit_code)
    except KeyboardInterrupt:
        deregister_service(STREAM)
        listener = get_listener_if_set(name="stream")

        if listener:
            listener.shutdown()
    except Exception:
        LOG.exception("(PID=%s) ST2 Stream API quit due to exception.",
                      os.getpid())
        return 1
    finally:
        _teardown()
Example #12
0
def main():
    try:
        _setup()

        collection_interval = cfg.CONF.garbagecollector.collection_interval
        sleep_delay = cfg.CONF.garbagecollector.sleep_delay
        garbage_collector = GarbageCollectorService(
            collection_interval=collection_interval, sleep_delay=sleep_delay)
        exit_code = garbage_collector.run()
    except SystemExit as exit_code:
        deregister_service(GARBAGE_COLLECTOR)
        return exit_code
    except:
        LOG.exception("(PID:%s) GarbageCollector quit due to exception.",
                      os.getpid())
        return FAILURE_EXIT_CODE
    finally:
        _teardown()

    return exit_code
Example #13
0
def _run_scheduler():
    LOG.info("(PID=%s) Scheduler started.", os.getpid())

    # Lazy load these so that decorator metrics are in place.
    from st2actions.scheduler import (
        handler as scheduler_handler,
        entrypoint as scheduler_entrypoint,
    )

    handler = scheduler_handler.get_handler()
    entrypoint = scheduler_entrypoint.get_scheduler_entrypoint()

    # TODO: Remove this try block for _cleanup_policy_delayed in v3.2.
    # This is a temporary cleanup to remove executions in deprecated policy-delayed status.
    try:
        handler._cleanup_policy_delayed()
    except Exception:
        LOG.exception(
            "(PID=%s) Scheduler unable to perform migration cleanup.",
            os.getpid())

    # TODO: Remove this try block for _fix_missing_action_execution_id in v3.2.
    # This is a temporary fix to auto-populate action_execution_id.
    try:
        handler._fix_missing_action_execution_id()
    except Exception:
        LOG.exception(
            "(PID=%s) Scheduler unable to populate action_execution_id.",
            os.getpid())

    try:
        handler.start()
        entrypoint.start()

        # Wait on handler first since entrypoint is more durable.
        handler.wait() or entrypoint.wait()
    except (KeyboardInterrupt, SystemExit):
        LOG.info("(PID=%s) Scheduler stopped.", os.getpid())

        errors = False

        try:
            deregister_service(service=SCHEDULER)
            handler.shutdown()
            entrypoint.shutdown()
        except:
            LOG.debug("Unable to shutdown scheduler.", exc_info=True)
            errors = True

        if errors:
            return 1
    except:
        LOG.exception("(PID=%s) Scheduler unexpectedly stopped.", os.getpid())

        try:
            handler.shutdown()
            entrypoint.shutdown()
        except:
            LOG.exception("Unable to shutdown scheduler.")

        return 1

    return 0