def _main(config=None, host=None, port=None, logfile=None, debug=None, daemon=None, uid=None, gid=None, pidfile=None, umask=None, rundir=None): # Note that we must initialize the configuration before we enter the context # block; however, we _cannot_ initialize logging until we are in the context block # (so we defer that until the context_serve call.) init_config(config) if host is not None: global_config.set('coilmq', 'listen_addr', host) if port is not None: global_config.set('coilmq', 'listen_port', str(port)) if daemon and is_nt: warnings.warn("Daemon context is not available for NT platform") # in an on-daemon mode, we use a dummy context objectx # so we can use the same run-server code as the daemon version. context = pydaemon.DaemonContext(uid=uid, gid=gid, pidfile=pid.PidFile(pidname=pidfile) if pidfile else None, umask=int(umask, 8), working_directory=rundir) if daemon and pydaemon else contextmanager(lambda: (yield))() context_serve(context, config, host, port, logfile, debug, daemon, uid, gid, pidfile, umask, rundir)
def startSTOMPBroker(config, serverUpEvent, tries=-1, delay=1, backoff=1.5): """ @param tries number of times to retry starting the broker. < 0 means infinitely many. @param delay number of seconds to wait after the first failed attempt @param backoff factor by which the delay will be incremented after a failure. """ #stomp broker mtries = tries mdelay = delay coilserver = None from coilmq.config import config as coilconfig if config.has_section('coilmq'): for k,v in config.items('coilmq'): coilconfig.set('coilmq', k, v) logger.debug("Set %s to %s for coilmq config." % (k,v)) while True: try: coilserver = coilmq.start.server_from_config(coilconfig) logger.info("Stomp server listening on %s:%s" % \ coilserver.server_address) serverUpEvent.set() coilserver.serve_forever() except IOError as ex: logger.error("Exception while starting coilmq broker: '%s'", ex) if mtries != 0: logger.debug("Retrying coilmq startup in %.1f seconds...", mdelay) time.sleep(mdelay) mdelay *= backoff mtries -= 1 else: logger.debug("Ran out of trials (tried %d times) for coilmq startup. Giving up.", tries) break finally: if coilserver: coilserver.server_close()
def startSTOMPBroker(config, serverUpEvent, tries=-1, delay=1, backoff=1.5): """ @param tries number of times to retry starting the broker. < 0 means infinitely many. @param delay number of seconds to wait after the first failed attempt @param backoff factor by which the delay will be incremented after a failure. """ #stomp broker mtries = tries mdelay = delay coilserver = None from coilmq.config import config as coilconfig if config.has_section('coilmq'): for k, v in config.items('coilmq'): coilconfig.set('coilmq', k, v) logger.debug("Set %s to %s for coilmq config." % (k, v)) while True: try: coilserver = coilmq.start.server_from_config(coilconfig) logger.info("Stomp server listening on %s:%s" % \ coilserver.server_address) serverUpEvent.set() coilserver.serve_forever() except IOError as ex: logger.error("Exception while starting coilmq broker: '%s'", ex) if mtries != 0: logger.debug("Retrying coilmq startup in %.1f seconds...", mdelay) time.sleep(mdelay) mdelay *= backoff mtries -= 1 else: logger.debug( "Ran out of trials (tried %d times) for coilmq startup. Giving up.", tries) break finally: if coilserver: coilserver.server_close()
def _main(config=None, host=None, port=None, logfile=None, debug=None, daemon=None, uid=None, gid=None, pidfile=None, umask=None, rundir=None): # Note that we must initialize the configuration before we enter the context # block; however, we _cannot_ initialize logging until we are in the context block # (so we defer that until the context_serve call.) init_config(config) if host is not None: global_config.set('coilmq', 'listen_addr', host) if port is not None: global_config.set('coilmq', 'listen_port', str(port)) if daemon and is_nt: warnings.warn("Daemon context is not available for NT platform") # in an on-daemon mode, we use a dummy context objectx # so we can use the same run-server code as the daemon version. context = pydaemon.DaemonContext( uid=uid, gid=gid, pidfile=pid.PidFile(pidname=pidfile) if pidfile else None, umask=int(umask, 8), working_directory=rundir) if daemon and pydaemon else contextmanager( lambda: (yield))() context_serve(context, config, host, port, logfile, debug, daemon, uid, gid, pidfile, umask, rundir)
""" m_tries = tries m_delay = delay m_server = None try: from coilmq.config import config as broker_config import coilmq.start except ImportError, e: print "Import error: %s\nPlease check." % e exit() if config.has_section('broker'): for (attribute, value) in config.items('broker'): if attribute != 'name': broker_config.set('coilmq', attribute, value) logger.debug("[coilmq] %s = %s" % (attribute, value)) broker_server = None while True: try: broker_server = coilmq.start.server_from_config(broker_config) logger.info("Stomp server listening on %s:%s" % broker_server.server_address) server_event.set() broker_server.serve_forever() except (KeyboardInterrupt, SystemExit): logger.info("Stomp server stopped by user interrupt.") raise SystemExit() except IOError as ex: logger.error("Exception while starting coilmq broker: '%s'", ex)
def main(): """ Main entry point for running a socket server from the commandline. This method will read in options from the commandline and call the L{config.init_config} method to get everything setup. Then, depending on whether deamon mode was specified or not, the process may be forked (or not) and the server will be started. """ parser = OptionParser() parser.add_option("-c", "--config", dest="configfile", help="Read configuration from FILE. (CLI options override config file.)", metavar="FILE") parser.add_option("-b", "--host", dest="listen_addr", help="Listen on specified address (default 0.0.0.0)", metavar="ADDR") parser.add_option("-p", "--port", dest="listen_port", help="Listen on specified port (default 61613)", type="int", metavar="PORT") parser.add_option("-l", "--logfile", dest="logfile", help="Log to specified file (unless logging configured in config file).", metavar="FILE") parser.add_option("--debug", action="store_true", dest="debug", default=False, help="Sets logging to debug (unless logging configured in config file).") parser.add_option("-d", "--daemon", action="store_true", dest="daemon", default=False, help="Run server as a daemon (default False).") parser.add_option("-u", "--uid", dest="uid", help="The user/UID to use for daemon process.", metavar="UID") parser.add_option("-g", "--gid", dest="gid", help="The group/GID to use for daemon process.", metavar="GID") parser.add_option("--pidfile", dest="pidfile", help="The PID file to use.", metavar="FILE") parser.add_option("--umask", dest="umask", help="Umask (octal) to apply for daemonized process.", metavar="MASK") parser.add_option('--rundir', dest="rundir", help="The working directory to use for the daemonized process (default /).", metavar="DIR") (options, args) = parser.parse_args() # Note that we must initialize the configuration before we enter the context # block; however, we _cannot_ initialize logging until we are in the context block # (so we defer that until the context_serve call.) init_config(options.configfile) if options.listen_addr is not None: global_config.set('coilmq', 'listen_addr', options.listen_addr) if options.listen_port is not None: global_config.set('coilmq', 'listen_port', str(options.listen_port)) if options.daemon: if not daemon_support: raise ConfigError("This environment/platform does not support running as daemon. (Are you running on *nix and did you install python-daemon package?)") else: context = daemon.DaemonContext() if options.uid is not None: context.uid = options.uid if options.gid is not None: context.gid = options.gid if options.pidfile is not None: context.pidfile = lockfile.FileLock(options.pidfile) if options.umask is not None: context.umask = int(options.umask, 8) if options.rundir is not None: context.working_directory = options.rundir context_serve(options, context) else: # Non-daemon mode, so we use a dummy context objectx # so we can use the same run-server code as the daemon version. class DumbContext(object): def __enter__(self): pass def __exit__(self, type, value, traceback): pass context_serve(options, DumbContext())
def main(): """ Main entry point for running a socket server from the commandline. This method will read in options from the commandline and call the L{config.init_config} method to get everything setup. Then, depending on whether deamon mode was specified or not, the process may be forked (or not) and the server will be started. """ parser = OptionParser() parser.add_option( "-c", "--config", dest="configfile", help= "Read configuration from FILE. (CLI options override config file.)", metavar="FILE") parser.add_option("-b", "--host", dest="listen_addr", help="Listen on specified address (default 127.0.0.1)", metavar="ADDR") parser.add_option("-p", "--port", dest="listen_port", help="Listen on specified port (default 61613)", type="int", metavar="PORT") parser.add_option( "-l", "--logfile", dest="logfile", help= "Log to specified file (unless logging configured in config file).", metavar="FILE") parser.add_option( "--debug", action="store_true", dest="debug", default=False, help="Sets logging to debug (unless logging configured in config file)." ) parser.add_option("-d", "--daemon", action="store_true", dest="daemon", default=False, help="Run server as a daemon (default False).") parser.add_option("-u", "--uid", dest="uid", help="The user/UID to use for daemon process.", metavar="UID") parser.add_option("-g", "--gid", dest="gid", help="The group/GID to use for daemon process.", metavar="GID") parser.add_option("--pidfile", dest="pidfile", help="The PID file to use.", metavar="FILE") parser.add_option("--umask", dest="umask", help="Umask (octal) to apply for daemonized process.", metavar="MASK") parser.add_option( '--rundir', dest="rundir", help= "The working directory to use for the daemonized process (default /).", metavar="DIR") (options, args) = parser.parse_args() # Note that we must initialize the configuration before we enter the context # block; however, we _cannot_ initialize logging until we are in the context block # (so we defer that until the context_serve call.) init_config(options.configfile) if options.listen_addr is not None: global_config.set('coilmq', 'listen_addr', options.listen_addr) if options.listen_port is not None: global_config.set('coilmq', 'listen_port', str(options.listen_port)) if options.daemon: if not daemon_support: raise ConfigError( "This environment/platform does not support running as daemon. (Are you running on *nix and did you install python-daemon package?)" ) else: context = daemon.DaemonContext() if options.uid is not None: context.uid = options.uid if options.gid is not None: context.gid = options.gid if options.pidfile is not None: context.pidfile = lockfile.FileLock(options.pidfile) if options.umask is not None: context.umask = int(options.umask, 8) if options.rundir is not None: context.working_directory = options.rundir context_serve(options, context) else: # Non-daemon mode, so we use a dummy context objectx # so we can use the same run-server code as the daemon version. class DumbContext(object): def __enter__(self): pass def __exit__(self, type, value, traceback): pass context_serve(options, DumbContext())