Example #1
0
    def main():
        usage = "usage: %prog [options]"
        parser = OptionParser(usage)
        parser.add_option("-c",
                          "--config",
                          action="store",
                          dest="config",
                          default=config_path)
        (options, args) = parser.parse_args()

        logfd = os.open(LOG_PATH, os.O_WRONLY | os.O_APPEND | os.O_CREAT, 0644)
        if logfd < 0:
            print sys.stderr, "ERROR: Failed to open log file (%s)" % LOG_PATH
            exit(1)
        # reinitialize python stdout/err
        sys.stdout.flush()
        sys.stderr.flush()
        os.dup2(logfd, 1)
        os.dup2(logfd, 2)
        os.close(logfd)
        devnull = os.open('/dev/null', os.O_RDONLY)
        os.dup2(devnull, 0)

        config = SafeConfigParser({
            'vm-min-mem':
            str(qmemman_algo.MIN_PREFMEM),
            'dom0-mem-boost':
            str(qmemman_algo.DOM0_MEM_BOOST),
            'cache-margin-factor':
            str(qmemman_algo.CACHE_FACTOR)
        })
        config.read(options.config)
        if config.has_section('global'):
            qmemman_algo.MIN_PREFMEM = parse_size(
                config.get('global', 'vm-min-mem'))
            qmemman_algo.DOM0_MEM_BOOST = parse_size(
                config.get('global', 'dom0-mem-boost'))
            qmemman_algo.CACHE_FACTOR = config.getfloat(
                'global', 'cache-margin-factor')

        print "values: %s, %s, %s" % (str(
            qmemman_algo.MIN_PREFMEM), str(
                qmemman_algo.DOM0_MEM_BOOST), str(qmemman_algo.CACHE_FACTOR))

        try:
            os.unlink(SOCK_PATH)
        except:
            pass
        os.umask(0)
        server = SocketServer.UnixStreamServer(SOCK_PATH, QMemmanReqHandler)
        os.umask(077)
        if os.fork() == 0:
            thread.start_new_thread(start_server, tuple([server]))
            XS_Watcher().watch_loop()
Example #2
0
    def main():
        usage = "usage: %prog [options]"
        parser = OptionParser(usage)
        parser.add_option("-c", "--config", action="store", dest="config", default=config_path)
        (options, args) = parser.parse_args()

        logfd = os.open(LOG_PATH, os.O_WRONLY | os.O_APPEND | os.O_CREAT, 0644)
        if logfd < 0:
            print sys.stderr, "ERROR: Failed to open log file (%s)" % LOG_PATH
            exit(1)
        # reinitialize python stdout/err
        sys.stdout.flush()
        sys.stderr.flush()
        os.dup2(logfd, 1)
        os.dup2(logfd, 2)
        os.close(logfd)
        devnull = os.open("/dev/null", os.O_RDONLY)
        os.dup2(devnull, 0)

        config = SafeConfigParser(
            {
                "vm-min-mem": str(qmemman_algo.MIN_PREFMEM),
                "dom0-mem-boost": str(qmemman_algo.DOM0_MEM_BOOST),
                "cache-margin-factor": str(qmemman_algo.CACHE_FACTOR),
            }
        )
        config.read(options.config)
        if config.has_section("global"):
            qmemman_algo.MIN_PREFMEM = parse_size(config.get("global", "vm-min-mem"))
            qmemman_algo.DOM0_MEM_BOOST = parse_size(config.get("global", "dom0-mem-boost"))
            qmemman_algo.CACHE_FACTOR = config.getfloat("global", "cache-margin-factor")

        print "values: %s, %s, %s" % (
            str(qmemman_algo.MIN_PREFMEM),
            str(qmemman_algo.DOM0_MEM_BOOST),
            str(qmemman_algo.CACHE_FACTOR),
        )

        try:
            os.unlink(SOCK_PATH)
        except:
            pass
        os.umask(0)
        server = SocketServer.UnixStreamServer(SOCK_PATH, QMemmanReqHandler)
        os.umask(077)
        if os.fork() == 0:
            thread.start_new_thread(start_server, tuple([server]))
            XS_Watcher().watch_loop()
Example #3
0
    def main():
        # setup logging
        ha_syslog = logging.handlers.SysLogHandler('/dev/log')
        ha_syslog.setFormatter(
            logging.Formatter('%(name)s[%(process)d]: %(message)s'))
        logging.root.addHandler(ha_syslog)

        # leave log for backwards compatibility
        ha_file = logging.FileHandler(LOG_PATH)
        ha_file.setFormatter(
            logging.Formatter('%(asctime)s %(name)s[%(process)d]: %(message)s'))
        logging.root.addHandler(ha_file)

        log = logging.getLogger('qmemman.daemon')

        usage = "usage: %prog [options]"
        parser = OptionParser(usage)
        parser.add_option("-c", "--config", action="store", dest="config", default=config_path)
        parser.add_option("-d", "--debug", action="store_true", dest="debug",
                          default=False, help="Enable debugging")
        (options, args) = parser.parse_args()

        if options.debug:
            logging.root.setLevel(logging.DEBUG)

        # close io
        sys.stdin.close()
        sys.stdout.close()
        sys.stderr.close()

        config = SafeConfigParser({
                'vm-min-mem': str(qmemman_algo.MIN_PREFMEM),
                'dom0-mem-boost': str(qmemman_algo.DOM0_MEM_BOOST),
                'cache-margin-factor': str(qmemman_algo.CACHE_FACTOR)
                })
        config.read(options.config)
        if config.has_section('global'):
            qmemman_algo.MIN_PREFMEM = parse_size(config.get('global', 'vm-min-mem'))
            qmemman_algo.DOM0_MEM_BOOST = parse_size(config.get('global', 'dom0-mem-boost'))
            qmemman_algo.CACHE_FACTOR = config.getfloat('global', 'cache-margin-factor')

        log.info('MIN_PREFMEM={qmemman_algo.MIN_PREFMEM}'
            ' DOM0_MEM_BOOST={qmemman_algo.DOM0_MEM_BOOST}'
            ' CACHE_FACTOR={qmemman_algo.CACHE_FACTOR}'.format(
                qmemman_algo=qmemman_algo))

        try:
            os.unlink(SOCK_PATH)
        except:
            pass

        log.debug('instantiating server')
        os.umask(0)
        server = SocketServer.UnixStreamServer(SOCK_PATH, QMemmanReqHandler)
        os.umask(077)

        # notify systemd
        nofity_socket = os.getenv('NOTIFY_SOCKET')
        if nofity_socket:
            log.debug('notifying systemd')
            s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
            if nofity_socket.startswith('@'):
                nofity_socket = '\0%s' % nofity_socket[1:]
            s.connect(nofity_socket)
            s.sendall("READY=1")
            s.close()

        thread.start_new_thread(start_server, tuple([server]))
        XS_Watcher().watch_loop()
    def main():
        # setup logging
        ha_syslog = logging.handlers.SysLogHandler('/dev/log')
        ha_syslog.setFormatter(
            logging.Formatter('%(name)s[%(process)d]: %(message)s'))
        logging.root.addHandler(ha_syslog)

        # leave log for backwards compatibility
        ha_file = logging.FileHandler(LOG_PATH)
        ha_file.setFormatter(
            logging.Formatter(
                '%(asctime)s %(name)s[%(process)d]: %(message)s'))
        logging.root.addHandler(ha_file)

        log = logging.getLogger('qmemman.daemon')

        usage = "usage: %prog [options]"
        parser = OptionParser(usage)
        parser.add_option("-c",
                          "--config",
                          action="store",
                          dest="config",
                          default=config_path)
        parser.add_option("-d",
                          "--debug",
                          action="store_true",
                          dest="debug",
                          default=False,
                          help="Enable debugging")
        (options, args) = parser.parse_args()

        if options.debug:
            logging.root.setLevel(logging.DEBUG)

        # close io
        sys.stdin.close()
        sys.stdout.close()
        sys.stderr.close()

        config = SafeConfigParser({
            'vm-min-mem':
            str(qmemman_algo.MIN_PREFMEM),
            'dom0-mem-boost':
            str(qmemman_algo.DOM0_MEM_BOOST),
            'cache-margin-factor':
            str(qmemman_algo.CACHE_FACTOR)
        })
        config.read(options.config)
        if config.has_section('global'):
            qmemman_algo.MIN_PREFMEM = parse_size(
                config.get('global', 'vm-min-mem'))
            qmemman_algo.DOM0_MEM_BOOST = parse_size(
                config.get('global', 'dom0-mem-boost'))
            qmemman_algo.CACHE_FACTOR = config.getfloat(
                'global', 'cache-margin-factor')

        log.info('MIN_PREFMEM={qmemman_algo.MIN_PREFMEM}'
                 ' DOM0_MEM_BOOST={qmemman_algo.DOM0_MEM_BOOST}'
                 ' CACHE_FACTOR={qmemman_algo.CACHE_FACTOR}'.format(
                     qmemman_algo=qmemman_algo))

        try:
            os.unlink(SOCK_PATH)
        except:
            pass

        log.debug('instantiating server')
        os.umask(0)
        server = SocketServer.UnixStreamServer(SOCK_PATH, QMemmanReqHandler)
        os.umask(077)

        # notify systemd
        nofity_socket = os.getenv('NOTIFY_SOCKET')
        if nofity_socket:
            log.debug('notifying systemd')
            s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
            if nofity_socket.startswith('@'):
                nofity_socket = '\0%s' % nofity_socket[1:]
            s.connect(nofity_socket)
            s.sendall("READY=1")
            s.close()

        thread.start_new_thread(start_server, tuple([server]))
        XS_Watcher().watch_loop()