Commits

desmaj  committed 33c792c

removed some unnecessary debug code; applied the patch from TRAC-157 (Thanks, Luke Macken!) to add daemonization support via python-daemon; updated the default orbited.cfg file to log to files instead of the console

  • Participants
  • Parent commits 8772354

Comments (0)

Files changed (4)

File daemon/orbited.cfg

 
 [logger_root]
 level = NOTSET
-handlers = console
+handlers = debug, info, error
 
 [logger_orbited]
 level = DEBUG
 
 [formatter_generic]
 format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
-datefmt = %H:%M:%S

File daemon/orbited/cometsession.py

 
 from orbited import transports
 
-DEBUG = True
-if DEBUG:
-    import objgraph
-    
 def setup_site(port):
     root = resource.Resource()
     static_files = static.File(os.path.join(os.path.dirname(__file__), 'static'))

File daemon/orbited/start.py

         default=False,
         help="run Orbited on port 8000 and MorbidQ on port 61613"
     )
+    parser.add_option( 
+        "-d", 
+        "--daemon", 
+        dest="daemon", 
+        action="store_true", 
+        default=False, 
+        help="run Orbited as a daemon (requires the python-daemon package)"
+        )
+    parser.add_option(
+        "--pid-file",
+        dest="pidfile",
+        default="/var/run/orbited/orbited.pid",
+        help=("use PIDFILE as the orbited daemon pid file",
+              "; defaults to '/var/run/orbited/orbited.pid'"),
+        )
     
     MemoryUtil.add_options_to_parser(parser)
     
     if options.version:
         print "Orbited version: %s" % (version,)
         sys.exit(0)
-
+    
+    logging.config.fileConfig(options.config)
+    global logger
+    logger = logging.getLogger(__name__)
+    
     if options.quickstart:
         config.map['[listen]'].append('http://:8000')
         config.map['[listen]'].append('stomp://:61613')
         config.map['[access]'][('localhost',61613)] = ['*']
-        print "Quickstarting Orbited"
+        logger.info("Quickstarting Orbited")
     else:
         # load configuration from configuration
         # file and from command line arguments.
         config.setup(options=options)
 
-    logging.config.fileConfig(options.config)
-    global logger
-    logger = logging.getLogger(__name__)
+    if options.daemon:
+        try:
+            from daemon import DaemonContext
+            from daemon.pidfile import PIDLockFile
+            pidlock = PIDLockFile(options.pidfile)
+            daemon = DaemonContext(pidfile=pidlock)
+            logger.debug('daemonizing with pid file %r', options.pidfile)
+            daemon.open()
+            logger.debug('daemonized!')
+        except Exception, exc:
+            logger.debug(exc)
     
     # NB: we need to install the reactor before using twisted.
     reactor_name = config.map['[global]'].get('reactor')

File daemon/orbited/transports/base.py

 from twisted.web import server, resource
 from twisted.internet import defer, reactor
 
-DEBUG = True
-if DEBUG:
-    import objgraph
-    
 logger = logging.getLogger('orbited.transports.base.CometTransport')
 
 class CometTransport(resource.Resource):
     HEARTBEAT_INTERVAL = 5
 
     def __init__(self, conn):
-        logger.debug('new transport: %s [%s]',
-                     self.__class__,
-                     len(objgraph.by_type(self.__class__)))
         self.conn = conn
         self.open = False
         self.closed = False