Exemple #1
0
class Start(Command):
    """Aggregator starter
    """
    parent = Aggregator

    options = [
        Option("-r",
               "--reload",
               action="store_true",
               dest="reload",
               default=False,
               help="Auto realod source on changes"),
        Option("-l",
               "--logging",
               metavar="str",
               default="none",
               help="Log level")
    ]

    def run(self, reload, logging, **kwargs):
        config = self._commandor_res

        if not config:
            self.error("You need specify --config\n")
            self.exit()

        configure_logging(logging)

        self.application = AggregatorApplication(config)
        ioloop = tornado.ioloop.IOLoop.instance()

        self.application.configure_app(ioloop)

        if reload:
            self.display("Autoreload enabled")
            autoreload.start(io_loop=ioloop, check_time=100)

        # Init signals handler
        signal.signal(signal.SIGTERM, self.sig_handler)

        # This will also catch KeyboardInterrupt exception
        signal.signal(signal.SIGINT, self.sig_handler)

        ioloop.start()

    def sig_handler(self, sig, frame):
        """Catch signal and init callback
        """
        tornado.ioloop.IOLoop.instance().add_callback(self.shutdown)

    def shutdown(self):
        """Stop server and add callback to stop i/o loop"""
        self.display("Shutting down service")
        self.application.shutdown()
        self.application.check_ready_to_stop()
Exemple #2
0
class Start(Command):
    """Aggregator starter
    """
    parent = Aggregator

    options = [
        Option("-r", "--reload", action="store_true",dest="reload", default=False,
               help="Auto realod source on changes"),
        Option("-l", "--logging", metavar="str", default="none",
               help="Log level")]

    def run(self, reload,  logging, **kwargs):
        config = self._commandor_res

        if not config:
            self.error("You need specify --config\n")
            self.exit()

        configure_logging(logging)

        self.application = AggregatorApplication(config)
        ioloop = tornado.ioloop.IOLoop.instance()

        self.application.configure_app(ioloop)

        if reload:
            self.display("Autoreload enabled")
            autoreload.start(io_loop=ioloop, check_time=100)

        # Init signals handler
        signal.signal(signal.SIGTERM, self.sig_handler)

        # This will also catch KeyboardInterrupt exception
        signal.signal(signal.SIGINT, self.sig_handler)

        ioloop.start()

    def sig_handler(self, sig, frame):
        """Catch signal and init callback
        """
        tornado.ioloop.IOLoop.instance().add_callback(self.shutdown)

    def shutdown(self):
        """Stop server and add callback to stop i/o loop"""
        self.display("Shutting down service")
        self.application.shutdown()
        self.application.check_ready_to_stop()