]> git.ipfire.org Git - ipfire.org.git/commitdiff
webapp: Refactor application launch
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Apr 2018 11:38:28 +0000 (13:38 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Apr 2018 11:38:28 +0000 (13:38 +0200)
This will start the webapp in a single-threaded mode
and we will need to launch multiple backends to provide
concurrency.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
webapp.py
webapp/__init__.py

index 0217543a60ca09b572e45314d9cadafd0bf37fbd..10318dcc42b60c327bdd34adbe49100e4228dc55 100755 (executable)
--- a/webapp.py
+++ b/webapp.py
@@ -1,32 +1,20 @@
-#!/usr/bin/python2.6
+#!/usr/bin/python
 
-import daemon
-import logging
-import logging.handlers
-import os
-import signal
-import sys
-
-#import tornado.httpserver
-#import tornado.ioloop
+import tornado.ioloop
 import tornado.options
 
-from webapp import Application
+tornado.options.define("port", type=int, default=8001, help="Port to listen on")
 
-if __name__ == "__main__":
-       app = Application(configfile="webapp.conf")
+from webapp import Application
 
-       context = daemon.DaemonContext(
-               working_directory=os.getcwd(),
-#              stdout=sys.stdout, stderr=sys.stderr, # XXX causes errors...
-       )
+def run():
+       tornado.options.parse_command_line()
 
-       context.signal_map = {
-               signal.SIGHUP  : app.reload,
-               signal.SIGTERM : app.shutdown,
-       }
+       # Initialize application
+       app = Application(configfile="webapp.conf")
+       app.listen(tornado.options.options.port)
 
-#      with context:
-#              app.run()
+       # Launch IOLoop
+       tornado.ioloop.IOLoop.current().start()
 
-       app.run()
+run()
index 69468f2e9a9c9629205e0ba3b4b03a45df57f42d..d4bcb5cf51d43addc3d7de90ba09c4270e6d54ea 100644 (file)
@@ -1,15 +1,11 @@
 #/usr/bin/python
 
 import logging
-import multiprocessing
 import os.path
-import simplejson
-import tornado.httpserver
 import tornado.locale
+import tornado.options
 import tornado.web
 
-from tornado.options import options
-
 import backend
 
 from handlers import *
@@ -22,7 +18,7 @@ class Application(tornado.web.Application):
                self.__backend = None
 
                settings = dict(
-                       debug = options.debug,
+                       debug = tornado.options.options.debug,
                        login_url = "/login",
                        template_path = os.path.join(BASEDIR, "templates"),
                        ui_methods = {
@@ -274,11 +270,6 @@ class Application(tornado.web.Application):
 
                logging.info("Successfully initialied application")
 
-               self.__running = True
-
-       def __del__(self):
-               logging.info("Shutting down application")
-
        @property
        def backend(self):
                if self.__backend is None:
@@ -291,39 +282,6 @@ class Application(tornado.web.Application):
 
                return self.__backend
 
-       @property
-       def ioloop(self):
-               return tornado.ioloop.IOLoop.instance()
-
-       def shutdown(self, *args):
-               logging.debug("Caught shutdown signal")
-               self.ioloop.stop()
-
-               self.__running = False
-
-       def run(self, port=8001):
-               logging.debug("Going to background")
-
-               http_server = tornado.httpserver.HTTPServer(self, xheaders=True)
-
-               num_processes = multiprocessing.cpu_count()
-
-               # If we are not running in debug mode, we can actually run multiple
-               # frontends to get best performance out of our service.
-               if not self.settings["debug"]:
-                       http_server.bind(port)
-                       http_server.start(num_processes=num_processes)
-               else:
-                       http_server.listen(port)
-
-               # All requests should be done after 30 seconds or they will be killed.
-               self.ioloop.set_blocking_log_threshold(30)
-
-               self.ioloop.start()
-
-       def reload(self):
-               logging.debug("Caught reload signal")
-
        def format_month_name(self, handler, month):
                _ = handler.locale.translate