Beispiel #1
0
def start():
    instance = SingleInstance(CLI_LOCK_PATH)
    try:
        instance.start()
    except InstanceAlreadyRunning:
        raise RetryFailed()
    return instance
Beispiel #2
0
def start():
    instance = SingleInstance(CLI_LOCK_PATH)
    try:
        instance.start()
    except InstanceAlreadyRunning:
        raise RetryFailed()
    return instance
Beispiel #3
0
def main():
    create_required_directories()
    init_logging()
    log = logging.getLogger(LOGGER_NAME)
    instance = SingleInstance(DAEMON_LOCK_PATH)
    try:
        instance.start()
    except InstanceAlreadyRunning:
        log.info("Daemon: Could not acquire single instance lock. Aborting.")
    else:
        try:
            with open(DAEMON_PID_PATH, "w") as f:
                f.write(str(os.getpid()))
            # TODO find out why the core isn't killing itself when the daemon is killed
            # TODO maybe I should handle the SIGTERM signal?
            monkey.patch_all()
            gevent.spawn(check_own_version, log)

            # Singletons
            core_client = CoreClient()
            ui_config = UIConfig()

            notifs_handler = NotificationsHandler()

            ui_listener = UIListener(UI_LISTENER_SOCKET_ADDRESS, core_client, ui_config, notifs_handler)
            core_listener = CoreListener(CORE_LISTENER_SOCKET_ADDRESS, core_client, ui_config, notifs_handler)
            core = Core(core_client)

            # Attempt to stop core, just in case there is a dangling core running
            core.stop()
            ui_listener_greenlet = gevent.spawn(ui_listener.start)
            core_listener_greenlet = gevent.spawn(core_listener.start)
            watchdog_greenlet = gevent.spawn(core.watchdog)

            Events.shutdown_required.wait()

            log.info("Daemon: Shutting down")

            ui_listener_greenlet.kill(block=True)
            core_listener_greenlet.kill(block=True)
            watchdog_greenlet.kill(block=True)

            # Sending a shutdown to the core should be enough to gracefully kill it,
            # but it might ignore us so after a little while, kill it forcefully
            try:
                core_client.shutdown()
                gevent.sleep(1)
            except Exception:
                log.warning(
                    "Daemon: Gracefull shutdown has thrown an exception. "
                    " Will ignore it just shut the core down forcefully."
                )
            core.stop()
        except Exception:
            log.exception("Daemon: An uncatched error occurred!")
        finally:
            instance.stop()
Beispiel #4
0
def main():
    create_required_directories()
    init_logging()
    log = logging.getLogger(LOGGER_NAME)
    instance = SingleInstance(DAEMON_LOCK_PATH)
    try:
        instance.start()
    except InstanceAlreadyRunning:
        log.info('Daemon: Could not acquire single instance lock. Aborting.')
    else:
        try:
            with open(DAEMON_PID_PATH, 'w') as f:
                f.write(str(os.getpid()))
            # TODO find out why the core isn't killing itself when the daemon is killed
            # TODO maybe I should handle the SIGTERM signal?
            monkey.patch_all()
            gevent.spawn(check_own_version, log)

            # Singletons
            core_client = CoreClient()
            ui_config = UIConfig()

            notifs_handler = NotificationsHandler()

            ui_listener = UIListener(UI_LISTENER_SOCKET_ADDRESS, core_client,
                                     ui_config, notifs_handler)
            core_listener = CoreListener(CORE_LISTENER_SOCKET_ADDRESS,
                                         core_client, ui_config,
                                         notifs_handler)
            core = Core(core_client)

            # Attempt to stop core, just in case there is a dangling core running
            core.stop()
            ui_listener_greenlet = gevent.spawn(ui_listener.start)
            core_listener_greenlet = gevent.spawn(core_listener.start)
            watchdog_greenlet = gevent.spawn(core.watchdog)

            Events.shutdown_required.wait()

            log.info('Daemon: Shutting down')

            ui_listener_greenlet.kill(block=True)
            core_listener_greenlet.kill(block=True)
            watchdog_greenlet.kill(block=True)

            # Sending a shutdown to the core should be enough to gracefully kill it,
            # but it might ignore us so after a little while, kill it forcefully
            try:
                core_client.shutdown()
                gevent.sleep(1)
            except Exception:
                log.warning(
                    'Daemon: Gracefull shutdown has thrown an exception. '
                    ' Will ignore it just shut the core down forcefully.')
            core.stop()
        except Exception:
            log.exception('Daemon: An uncatched error occurred!')
        finally:
            instance.stop()