Exemplo n.º 1
0
    def start(self):

        def kill_server(sig, frame):

            LOG.warning( 'Catch SIG: %d' % sig )

            tornado.ioloop.IOLoop.instance().stop()


        # ignore Broken Pipe signal
        signal.signal(signal.SIGPIPE, signal.SIG_IGN);
                            
        # catch kill signal
        signal.signal(signal.SIGINT, kill_server)
        signal.signal(signal.SIGQUIT, kill_server)
        signal.signal(signal.SIGTERM, kill_server)
        signal.signal(signal.SIGHUP, kill_server)

        for log_name in self.log_list:
            mownfish.util.log.setup(log_name)

        LOG.info('START TORNADO WEB SERVER ...')

        for key, value in sorted(options.items(), key=lambda d:d[0]):
            if key not in ('help', 'log_file_prefix', 'log_to_stderr') \
                    and value.value() is None:
                sys.stderr.write('must specify %s\n' % key)
                options.print_help()
                sys.exit(0)
            LOG.info('Options: (%s, %s)', key, value.value())

        try:
            sockets = tornado.netutil.bind_sockets(options.port,
                    address=options.bind_ip,
                    backlog=128)

            if not options.multiports:
                task_id = tornado.process.fork_processes(options.num_process)
            
            http_server =  \
                tornado.httpserver.HTTPServer(xheaders=True,
                                            request_callback=self.application)
            http_server.add_sockets(sockets)

            self.prepare()

            tornado.ioloop.IOLoop.instance().start()

            http_server.stop()
            tornado.ioloop.IOLoop.instance().stop()

            LOG.info('STOP TORNADO WEB SERVER ...')
        except socket.error as e:
            LOG.warning('Socket Error: %s' % str(e))
        except KeyboardInterrupt as e:
            LOG.warning('Gently Quit')
        except Exception as e:
            LOG.error('UnCaught Exception: %s' % e, exc_info=True)
Exemplo n.º 2
0
    def start(self):
        def kill_server(sig, frame):

            LOG.warning('Catch SIG: %d' % sig)

            tornado.ioloop.IOLoop.instance().stop()

        # ignore Broken Pipe signal
        signal.signal(signal.SIGPIPE, signal.SIG_IGN)

        # catch kill signal
        signal.signal(signal.SIGINT, kill_server)
        signal.signal(signal.SIGQUIT, kill_server)
        signal.signal(signal.SIGTERM, kill_server)
        signal.signal(signal.SIGHUP, kill_server)

        for log_name in self.log_list:
            mownfish.util.log.setup(log_name)

        LOG.info('START TORNADO WEB SERVER ...')

        for key, value in sorted(options.items(), key=lambda d: d[0]):
            if key not in ('help', 'log_file_prefix', 'log_to_stderr') \
                    and value.value() is None:
                sys.stderr.write('must specify %s\n' % key)
                options.print_help()
                sys.exit(0)
            LOG.info('Options: (%s, %s)', key, value.value())

        try:
            sockets = tornado.netutil.bind_sockets(options.port,
                                                   address=options.bind_ip,
                                                   backlog=128)

            if not options.multiports:
                task_id = tornado.process.fork_processes(options.num_process)

            http_server =  \
                tornado.httpserver.HTTPServer(xheaders=True,
                                            request_callback=self.application)
            http_server.add_sockets(sockets)

            self.prepare()

            tornado.ioloop.IOLoop.instance().start()

            http_server.stop()
            tornado.ioloop.IOLoop.instance().stop()

            LOG.info('STOP TORNADO WEB SERVER ...')
        except socket.error as e:
            LOG.warning('Socket Error: %s' % str(e))
        except KeyboardInterrupt as e:
            LOG.warning('Gently Quit')
        except Exception as e:
            LOG.error('UnCaught Exception: %s' % e, exc_info=True)
Exemplo n.º 3
0
    def start(self):
        def kill_server(sig, frame):

            LOG.warning('Catch SIG: %d' % sig)

            tornado.ioloop.IOLoop.instance().stop()

        # 忽略Broken Pipe信号
        signal.signal(signal.SIGPIPE, signal.SIG_IGN)

        # 处理kill信号
        signal.signal(signal.SIGINT, kill_server)
        signal.signal(signal.SIGQUIT, kill_server)
        signal.signal(signal.SIGTERM, kill_server)
        signal.signal(signal.SIGHUP, kill_server)

        LOG.info('START TORNADO WEB SERVER ...')

        for key, value in options.iteritems():
            LOG.info('Options: (%s, %s)', key, value.value())

        try:
            sockets = tornado.netutil.bind_sockets(options.port,
                                                   address=options.bind_ip,
                                                   backlog=128)

            http_server =  \
                tornado.httpserver.HTTPServer(xheaders=True, request_callback=TApplication())
            http_server.add_sockets(sockets)

            tt = timer_task.TimerTask()
            tt.start()

            tornado.ioloop.IOLoop.instance().start()

            http_server.stop()
            tornado.ioloop.IOLoop.instance().close()

            LOG.info('STOP TORNADO WEB SERVER ...')
        except socket.error as e:
            LOG.warning('Socket Error: %s', str(e))
        except KeyboardInterrupt as e:
            LOG.warning('Gently Quit')
        except Exception as e:
            LOG.error('UnCaught Exception: %s', e)
Exemplo n.º 4
0
 def on_connection_close(self):
     LOG.info('connection close.')
Exemplo n.º 5
0
 def on_connection_close(self):
     LOG.info('connection close.')