Exemple #1
0
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)
Exemple #2
0
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 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())
Exemple #4
0
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())