Example #1
0
def run_server(argv):
    import getopt
    do_daemon = True
    pidfile = None
    try:
        optlist, args = getopt.getopt(argv[1:], "nh?p:")
    except getopt.GetoptError:
        print(_DOC)
        sys.exit(2)

    for opt, optarg in optlist:
        if opt in ("-h", "-?"):
            print(_DOC)
            return
        elif opt == "-n":
            do_daemon = False
        elif opt == "-p":
            pidfile = optarg

    if do_daemon:
        from pycopia import daemonize
        daemonize.daemonize(pidfile=pidfile)

    logging.msg("qaagent", "initializing")
    h = pyro.register_server(PosixAgent())

    def _exit_checker(poller):
        if _EXIT:
            pyro.unregister_server(h)

    try:
        pyro.loop(2.0, _exit_checker)
    finally:
        if do_daemon and pidfile:
            os.unlink(pidfile)
Example #2
0
def run_server(argv):
    import getopt
    do_daemon = True
    pidfile = None
    try:
        optlist, args = getopt.getopt(argv[1:], "nh?p:")
    except getopt.GetoptError:
        print(_DOC)
        sys.exit(2)

    for opt, optarg in optlist:
        if opt in ("-h", "-?"):
            print(_DOC)
            return
        elif opt == "-n":
            do_daemon = False
        elif opt == "-p":
            pidfile = optarg

    if do_daemon:
        from pycopia import daemonize
        daemonize.daemonize(pidfile=pidfile)

    logging.msg("qaagent", "initializing")
    h = pyro.register_server(PosixAgent())
    def _exit_checker(poller):
        if _EXIT:
            pyro.unregister_server(h)
    try:
        pyro.loop(2.0, _exit_checker)
    finally:
        if do_daemon and pidfile:
            os.unlink(pidfile)
Example #3
0
def storaged(argv):
    """The Droid storage server.

  storaged [-h <serverhost>] [-p <serverport>] [-d <databasefile>] 
          [-l <logfile>] [-n] [-?]

  where:

      -h <host> is the server hostname to bind to.
      -p <port> is the TCP port to use (other than the default).
      -d <filename> specifies the Durus file to use for the database.
      -l <logfilename> file name to use for logging.
      -n Do NOT become a daemon, stay in foreground (for debugging).
      -? This help screen.

  Uses the configuration file /etc/droid/storage.conf to obtain the
  default option values.

  """

    import getopt
    from pycopia import daemonize
    from pycopia import basicconfig
    cf = basicconfig.get_config(
        os.path.join("/", "etc", "droid", "storage.conf"))
    host = cf.get("host", DEFAULT_HOST)
    port = cf.get("port", DEFAULT_PORT)
    DBFILE = os.path.expandvars(cf.get("dbfile"))
    LOGFILE = os.path.expandvars(cf.get("dblog"))
    del cf
    do_daemon = True

    try:
        optlist, args = getopt.getopt(argv[1:], "d:l:h:p:n?")
    except getopt.GetoptError:
        print storaged.__doc__
        sys.exit(2)

    for opt, optarg in optlist:
        if opt == "-d":
            DBFILE = optarg
        elif opt == "-l":
            LOGFILE = optarg
        elif opt == "-h":
            host = optarg
        elif opt == "-p":
            port = int(optarg)
        elif opt == "-n":
            do_daemon = False
        elif opt == "-?":
            print storaged.__doc__
            return 2

    if do_daemon:
        daemonize.daemonize(pidfile="/var/run/%s.pid" %
                            (os.path.basename(argv[0]), ))
    try:
        startDurus(host, port, LOGFILE, DBFILE)
    except KeyboardInterrupt:
        return
Example #4
0
def storaged(argv):
    """The Pycopia storage server.
    storaged [-h <serverhost>] [-p <serverport>] [-d <databasefile>] [-l <logfile>]
           [-n] [-?]

    where:

        -h is the server hostname to bind to.
        -p is the TCP port to use (other than the default)
        -d specifies the Durus file to use for the database.
        -l Log file name to use for logging.
        -n Do NOT become a daemon, stay in foreground (for debugging)
        -? This help screen.

    """
    import getopt
    from pycopia import basicconfig

    cf = basicconfig.get_config("storage.conf")
    host = cf.get("host", DEFAULT_HOST)
    port = cf.get("port", DEFAULT_PORT)
    DBFILE = os.path.expandvars(cf.get("dbfile"))
    LOGFILE = os.path.expandvars(cf.get("dblog"))
    del cf
    do_daemon = True

    try:
        optlist, args = getopt.getopt(argv[1:], "d:l:h:p:n?")
    except getopt.GetoptError:
        print storaged.__doc__
        sys.exit(2)

    for opt, optarg in optlist:
        if opt == "-d":
            DBFILE = optarg
        elif opt == "-l":
            LOGFILE = optarg
        elif  opt == "-h":
            host = optarg
        elif opt == "-p":
            port = int(optarg)
        elif opt == "-n":
            do_daemon = False
        elif opt == "-?":
            print storaged.__doc__
            return 2

    if do_daemon:
        from pycopia import daemonize
        daemonize.daemonize()
    try:
        start_durus(host, port, LOGFILE, DBFILE)
    except KeyboardInterrupt:
        return
Example #5
0
def storaged(argv):
    """The Pycopia storage server.
    storaged [-h <serverhost>] [-p <serverport>] [-d <databasefile>] [-l <logfile>]
           [-n] [-?]

    where:

        -h is the server hostname to bind to.
        -p is the TCP port to use (other than the default)
        -d specifies the Durus file to use for the database.
        -l Log file name to use for logging.
        -n Do NOT become a daemon, stay in foreground (for debugging)
        -? This help screen.

    """
    import getopt
    from pycopia import basicconfig

    cf = basicconfig.get_config("storage.conf")
    host = cf.get("host", DEFAULT_HOST)
    port = cf.get("port", DEFAULT_PORT)
    DBFILE = os.path.expandvars(cf.get("dbfile"))
    LOGFILE = os.path.expandvars(cf.get("dblog"))
    del cf
    do_daemon = True

    try:
        optlist, args = getopt.getopt(argv[1:], "d:l:h:p:n?")
    except getopt.GetoptError:
        print storaged.__doc__
        sys.exit(2)

    for opt, optarg in optlist:
        if opt == "-d":
            DBFILE = optarg
        elif opt == "-l":
            LOGFILE = optarg
        elif opt == "-h":
            host = optarg
        elif opt == "-p":
            port = int(optarg)
        elif opt == "-n":
            do_daemon = False
        elif opt == "-?":
            print storaged.__doc__
            return 2

    if do_daemon:
        from pycopia import daemonize
        daemonize.daemonize()
    try:
        start_durus(host, port, LOGFILE, DBFILE)
    except KeyboardInterrupt:
        return
Example #6
0
def start(config):
    if config.DAEMON:
        from pycopia import daemonize
        from pycopia import logfile
        lf = logfile.ManagedStdio(config.LOGFILENAME)
        daemonize.daemonize(lf, pidfile=config.PIDFILE)
    else:
        lf = sys.stdout
        fo = file(config.PIDFILE, "w")
        fo.write("%s\n" % (os.getpid(),))
        fo.close()
    start_proc_manager(config, lf)
Example #7
0
def start(config):
    if config.DAEMON:
        from pycopia import daemonize
        from pycopia import logfile
        lf = logfile.ManagedStdio(config.LOGFILENAME)
        daemonize.daemonize(lf, pidfile=config.PIDFILE)
    else:
        lf = sys.stdout
        fo = file(config.PIDFILE, "w")
        fo.write("%s\n" % (os.getpid(), ))
        fo.close()
    start_proc_manager(config, lf)
Example #8
0
def start(config):
    setup(config)
    if config.DAEMON:
        from pycopia import daemonize
        from pycopia import logfile
        lf = logfile.ManagedStdio(config.LOGFILENAME)
        daemonize.daemonize(lf, pidfile=config.PIDFILE)
    else:
        lf = sys.stderr
        with open(config.PIDFILE, "w") as fo:
            fo.write("{}\n".format(os.getpid()))
    start_proc_manager(config, lf)
Example #9
0
def run_server(argv):
    """pyserver [-nh?] 

    Starts the Posix Client Operations Server.

    Where:
        -n = Do NOT run as a daemon, but stay in foreground.

    """
    global _EXIT
    from pycopia import daemonize
    import getopt
    do_daemon = True
    try:
        optlist, args = getopt.getopt(argv[1:], "nh?")
    except getopt.GetoptError:
        print run_server.__doc__
        sys.exit(2)

    for opt, optarg in optlist:
        if opt in ("-h", "-?"):
            print run_server.__doc__
            return
        elif opt == "-n":
            do_daemon = False

    if do_daemon:
        daemonize.daemonize()

    Pyro.core.initServer(banner=0, storageCheck=0)
    Log.msg("ClientServer", "initializing")

    ns = Pyro.naming.NameServerLocator().getNS()

    daemon = Pyro.core.Daemon()
    daemon.useNameServer(ns)

    uri = daemon.connectPersistent(
        ClientServer(), ":Client.%s" % (os.uname()[1].split(".")[0], ))

    while True:
        try:
            daemon.handleRequests(2.0)
            if _EXIT:
                return
            asyncio.poller.poll(0)
        except KeyboardInterrupt:
            break
        except:
            ex, val, tb = sys.exc_info()
            print >> sys.stderr, ex, val
Example #10
0
def run_server(argv):
    """pyserver [-nh?] 

    Starts the Posix Client Operations Server.

    Where:
        -n = Do NOT run as a daemon, but stay in foreground.

    """
    global _EXIT
    from pycopia import daemonize
    import getopt
    do_daemon = True
    try:
        optlist, args = getopt.getopt(argv[1:], "nh?")
    except getopt.GetoptError:
        print run_server.__doc__
        sys.exit(2)

    for opt, optarg in optlist:
        if opt in ("-h", "-?"):
            print run_server.__doc__
            return
        elif opt == "-n":
            do_daemon = False

    if do_daemon:
        daemonize.daemonize()

    Pyro.core.initServer(banner=0, storageCheck=0)
    Log.msg("ClientServer", "initializing")

    ns=Pyro.naming.NameServerLocator().getNS()

    daemon=Pyro.core.Daemon()
    daemon.useNameServer(ns)

    uri=daemon.connectPersistent(ClientServer(), ":Client.%s" % (os.uname()[1].split(".")[0],))

    while True:
        try:
            daemon.handleRequests(2.0)
            if _EXIT:
                return
            asyncio.poller.poll(0)
        except KeyboardInterrupt:
            break
        except:
            ex, val, tb = sys.exc_info()
            print >>sys.stderr, ex, val
Example #11
0
def qanameserverd(argv):
    import getopt
    do_daemon = True
    try:
        optlist, args = getopt.getopt(argv[1:], "nh?")
    except getopt.GetoptError:
        print(_DOC)
        sys.exit(2)

    for opt, optarg in optlist:
        if opt in ("-h", "-?"):
            print(_DOC)
            return
        elif opt == "-n":
            do_daemon = False

    if do_daemon:
        from pycopia import daemonize
        daemonize.daemonize()

    naming.startNSloop()
Example #12
0
def qanameserverd(argv):
    import getopt
    do_daemon = True
    try:
        optlist, args = getopt.getopt(argv[1:], "nh?")
    except getopt.GetoptError:
        print(_DOC)
        sys.exit(2)

    for opt, optarg in optlist:
        if opt in ("-h", "-?"):
            print(_DOC)
            return
        elif opt == "-n":
            do_daemon = False

    if do_daemon:
        from pycopia import daemonize
        daemonize.daemonize()

    naming.startNSloop()
Example #13
0
def run_server(argv):
    username = None
    do_daemon = True
    debug = False
    killserver = False
    try:
        optlist, args = getopt.getopt(argv[1:], "dnh?kl:f:p:s:")
    except getopt.GetoptError:
        print(run_server._doc % (argv[0], ))
        return

    if len(args) > 0:
        servername = args[0]
    else:
        servername = os.path.basename(argv[0])

    logfilename = "/var/log/%s.log" % (servername, )
    cffilename = "/etc/pycopia/%s.conf" % (servername, )
    pidfile = "/var/run/%s.pid" % (servername, )
    socketpath = '/tmp/%s.sock' % (servername, )

    for opt, optarg in optlist:
        if opt == "-n":
            do_daemon = False
        elif opt == "-k":
            killserver = True
        elif opt == "-d":
            debug = True
        elif opt == "-u":
            username = optarg
        elif opt == "-l":
            logfilename = optarg
        elif opt == "-f":
            cffilename = optarg
        elif opt == "-p":
            pidfile = optarg
        elif opt == "-s":
            socketpath = optarg
        elif opt in ("-h", "-?"):
            print(run_server._doc % (argv[0], ))
            return 2

    try:
        config = basicconfig.get_config(cffilename,
                                        CONFIGFILE=cffilename,
                                        PIDFILE=pidfile,
                                        SOCKETPATH=socketpath,
                                        LOGFILENAME=logfilename,
                                        DEBUG=debug,
                                        SERVERNAME=servername)
    except:
        ex, val, tb = sys.exc_info()
        logging.warn("Could not get server config: %s (%s)" % (ex, val))
        return 1

    if username:
        config.USERNAME = username

    if killserver:
        kill_server(config)
        return 0

    if check4server(config):
        logging.warn("Server %r already running on socket %r." %
                     (servername, socketpath))
        return 1

    if do_daemon and not debug:
        from pycopia import daemonize
        from pycopia import logfile
        lf = logfile.ManagedStdio(logfilename)
        daemonize.daemonize(lf, pidfile=pidfile)
    else:  # for controller
        fo = open(pidfile, "w")
        fo.write("%s\n" % (os.getpid(), ))
        fo.close()
        del fo

    server = get_server(config)
    return int(server.run())
Example #14
0
def run_server(argv):
    username = None
    do_daemon = True
    debug = False
    killserver = False
    try:
        optlist, args = getopt.getopt(argv[1:], "dnh?kl:f:p:s:")
    except getopt.GetoptError:
        print run_server._doc % (argv[0],)
        return

    if len(args) > 0:
        servername = args[0]
    else:
        servername = os.path.basename(argv[0])

    logfilename = "/var/log/%s.log" % (servername,)
    cffilename = "/etc/pycopia/%s.conf" % (servername,)
    pidfile="/var/run/%s.pid" % (servername,)
    socketpath = '/tmp/%s.sock' % (servername,)

    for opt, optarg in optlist:
        if opt == "-n":
            do_daemon = False
        elif opt == "-k":
            killserver = True
        elif opt == "-d":
            debug = True
        elif opt == "-u":
            username = optarg
        elif opt == "-l":
            logfilename = optarg
        elif opt == "-f":
            cffilename = optarg
        elif opt == "-p":
            pidfile = optarg
        elif opt == "-s":
            socketpath = optarg
        elif opt in ("-h", "-?"):
            print run_server._doc % (argv[0],)
            return 2

    try:
        config = basicconfig.get_config(cffilename, 
                    CONFIGFILE=cffilename,
                    PIDFILE=pidfile,
                    SOCKETPATH=socketpath,
                    LOGFILENAME=logfilename, 
                    DEBUG=debug, 
                    SERVERNAME=servername)
    except:
        ex, val, tb = sys.exc_info()
        print >>sys.stderr, "Could not get server config: %s (%s)" % (ex, val)
        return 1

    if username:
        config.USERNAME = username

    if killserver:
        kill_server(config)
        return 0

    if check4server(config):
        print >>sys.stderr, "Server %r already running on socket %r." % (servername, socketpath)
        return 1

    if do_daemon and not debug:
        from pycopia import daemonize
        from pycopia import logfile
        lf = logfile.ManagedStdio(logfilename)
        daemonize.daemonize(lf, pidfile=pidfile)
    else: # for controller
        fo = open(pidfile, "w")
        fo.write("%s\n" % (os.getpid(),))
        fo.close()
        del fo

    server = get_server(config)
    return int(server.run())
Example #15
0
def run_server(argv):
    username = None
    do_daemon = True
    debug = False
    killserver = False
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "dnh?kl:f:p:s:")
    except getopt.GetoptError:
        print(run_server._doc.format(procname=argv[0]))
        return

    if len(args) > 0:
        servername = args[0]
    else:
        servername = os.path.basename(argv[0])

    logfilename = "/var/log/{}.log".format(servername)
    cffilename = "/etc/pycopia/{}.conf".format(servername)
    pidfile = "/var/run/{}.pid".format(servername)
    socketpath = '/tmp/{}.sock'.format(servername)

    for opt, optarg in optlist:
        if opt == "-n":
            do_daemon = False
        elif opt == "-k":
            killserver = True
        elif opt == "-d":
            from pycopia import autodebug  # noqa
            debug = True
        elif opt == "-u":
            username = optarg
        elif opt == "-l":
            logfilename = optarg
        elif opt == "-f":
            cffilename = optarg
        elif opt == "-p":
            pidfile = optarg
        elif opt == "-s":
            socketpath = optarg
        elif opt in ("-h", "-?"):
            print(run_server._doc.format(procname=argv[0]))
            return 2

    try:
        config = basicconfig.get_config(cffilename,
                                        CONFIGFILE=cffilename,
                                        PIDFILE=pidfile,
                                        SOCKETPATH=socketpath,
                                        LOGFILENAME=logfilename,
                                        DEBUG=debug,
                                        SERVERNAME=servername)
    except:
        ex, val, tb = sys.exc_info()
        logging.warn(
            "Could not get server config: {} ({})".format(ex.__name__, val))
        return 1
    config.update(longopts)

    if username:
        config.USERNAME = username

    if killserver:
        kill_server(config)
        return 0

    if check4server(config):
        logging.warn(
            "Server {!r} already running on socket {!r}.".format(servername,
                                                                 socketpath))
        return 1

    if do_daemon and not debug:
        from pycopia import daemonize
        from pycopia import logfile
        lf = logfile.ManagedStdio(logfilename)
        daemonize.daemonize(lf, pidfile=pidfile)
    else:  # for controller
        with open(pidfile, "w") as fo:
            fo.write("{}\n".format(os.getpid()))

    server = get_server(config)
    return int(server.run())
Example #16
0
def run_server(argv):
    username = None
    do_daemon = True
    debug = False
    killserver = False
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "dnh?kl:f:p:s:")
    except getopt.GetoptError:
        print(run_server._doc.format(procname=argv[0]))
        return

    if len(args) > 0:
        servername = args[0]
    else:
        servername = os.path.basename(argv[0])

    logfilename = "/var/log/{}.log".format(servername)
    cffilename = "/etc/pycopia/{}.conf".format(servername)
    pidfile = "/var/run/{}.pid".format(servername)
    socketpath = '/tmp/{}.sock'.format(servername)

    for opt, optarg in optlist:
        if opt == "-n":
            do_daemon = False
        elif opt == "-k":
            killserver = True
        elif opt == "-d":
            from pycopia import autodebug  # noqa
            debug = True
        elif opt == "-u":
            username = optarg
        elif opt == "-l":
            logfilename = optarg
        elif opt == "-f":
            cffilename = optarg
        elif opt == "-p":
            pidfile = optarg
        elif opt == "-s":
            socketpath = optarg
        elif opt in ("-h", "-?"):
            print(run_server._doc.format(procname=argv[0]))
            return 2

    try:
        config = basicconfig.get_config(cffilename,
                                        CONFIGFILE=cffilename,
                                        PIDFILE=pidfile,
                                        SOCKETPATH=socketpath,
                                        LOGFILENAME=logfilename,
                                        DEBUG=debug,
                                        SERVERNAME=servername)
    except:
        ex, val, tb = sys.exc_info()
        logging.warn("Could not get server config: {} ({})".format(
            ex.__name__, val))
        return 1
    config.update(longopts)

    if username:
        config.USERNAME = username

    if killserver:
        kill_server(config)
        return 0

    if check4server(config):
        logging.warn("Server {!r} already running on socket {!r}.".format(
            servername, socketpath))
        return 1

    if do_daemon and not debug:
        from pycopia import daemonize
        from pycopia import logfile
        lf = logfile.ManagedStdio(logfilename)
        daemonize.daemonize(lf, pidfile=pidfile)
    else:  # for controller
        with open(pidfile, "w") as fo:
            fo.write("{}\n".format(os.getpid()))

    server = get_server(config)
    return int(server.run())