def main(): CONF.register_cli_opt( cfg.BoolOpt('daemon', short='D', default=False, help='Run as a long-running process. When not ' 'specified (the default) run the scrub operation ' 'once and then exits. When specified do not exit ' 'and run scrub on wakeup_time interval as ' 'specified in the config.')) CONF.register_opt(cfg.IntOpt('wakeup_time', default=300)) try: config.parse_args() log.setup('glance') glance.store.create_stores() glance.store.verify_default_store() app = scrubber.Scrubber(glance.store) if CONF.daemon: server = scrubber.Daemon(CONF.wakeup_time) server.start(app) server.wait() else: import eventlet pool = eventlet.greenpool.GreenPool(1000) app.run(pool) except RuntimeError as e: sys.exit("ERROR: %s" % e)
def main(): CONF.register_cli_opts(scrubber.scrubber_cmd_cli_opts) CONF.register_opts(scrubber.scrubber_cmd_opts) try: config.parse_args() log.setup('glance') glance_store.register_opts(config.CONF) glance_store.create_stores(config.CONF) glance_store.verify_default_store() app = scrubber.Scrubber(glance_store) if CONF.daemon: server = scrubber.Daemon(CONF.wakeup_time) server.start(app) systemd.notify_once() server.wait() else: import eventlet pool = eventlet.greenpool.GreenPool(1000) app.run(pool) except RuntimeError as e: sys.exit("ERROR: %s" % e)
def main(): # Used on Window, ensuring that a single scrubber can run at a time. mutex = None mutex_acquired = False try: if os.name == 'nt': # We can't rely on process names on Windows as there may be # wrappers with the same name. mutex = os_win_utilsfactory.get_mutex( name='Global\\glance-scrubber') mutex_acquired = mutex.acquire(timeout_ms=0) CONF.register_cli_opts(scrubber.scrubber_cmd_cli_opts) CONF.register_opts(scrubber.scrubber_cmd_opts) config.parse_args() logging.setup(CONF, 'glance') glance_store.register_opts(config.CONF) glance_store.create_stores(config.CONF) glance_store.verify_default_store() if CONF.restore and CONF.daemon: sys.exit("ERROR: The restore and daemon options should not be set " "together. Please use either of them in one request.") app = scrubber.Scrubber(glance_store) if CONF.restore: if os.name == 'nt': scrubber_already_running = not mutex_acquired else: scrubber_already_running = scrubber_already_running_posix() if scrubber_already_running: already_running_msg = ( "ERROR: glance-scrubber is already running. " "Please ensure that the daemon is stopped.") sys.exit(already_running_msg) app.revert_image_status(CONF.restore) elif CONF.daemon: server = scrubber.Daemon(CONF.wakeup_time) server.start(app) server.wait() else: app.run() except (exception.ImageNotFound, exception.Conflict) as e: sys.exit("ERROR: %s" % e) except RuntimeError as e: sys.exit("ERROR: %s" % e) finally: if mutex and mutex_acquired: mutex.release()
def main(): CONF.register_cli_opts(scrubber.scrubber_cmd_cli_opts) CONF.register_opts(scrubber.scrubber_cmd_opts) try: config.parse_args() logging.setup(CONF, 'glance') glance_store.register_opts(config.CONF) glance_store.create_stores(config.CONF) glance_store.verify_default_store() app = scrubber.Scrubber(glance_store) if CONF.daemon: server = scrubber.Daemon(CONF.wakeup_time) server.start(app) server.wait() else: app.run() except RuntimeError as e: sys.exit("ERROR: %s" % e)
def main(): CONF.register_cli_opts(scrubber.scrubber_cmd_cli_opts) CONF.register_opts(scrubber.scrubber_cmd_opts) try: config.parse_args() logging.setup(CONF, 'glance') glance_store.register_opts(config.CONF) glance_store.create_stores(config.CONF) glance_store.verify_default_store() app = scrubber.Scrubber(glance_store) if CONF.restore and CONF.daemon: sys.exit("ERROR: The restore and daemon options should not be set " "together. Please use either of them in one request.") if CONF.restore: # Try to check the glance-scrubber is running or not. # 1. Try to find the pid file if scrubber is controlled by # glance-control # 2. Try to check the process name. error_str = ("ERROR: The glance-scrubber process is running under " "daemon. Please stop it first.") pid_file = '/var/run/glance/glance-scrubber.pid' if os.path.exists(os.path.abspath(pid_file)): sys.exit(error_str) for glance_scrubber_name in ['glance-scrubber', 'glance.cmd.scrubber']: cmd = subprocess.Popen( ['/usr/bin/pgrep', '-f', glance_scrubber_name], stdout=subprocess.PIPE, shell=False) pids, _ = cmd.communicate() # The response format of subprocess.Popen.communicate() is # diffderent between py2 and py3. It's "string" in py2, but # "bytes" in py3. if isinstance(pids, bytes): pids = pids.decode() self_pid = os.getpid() if pids.count('\n') > 1 and str(self_pid) in pids: # One process is self, so if the process number is > 1, it # means that another glance-scrubber process is running. sys.exit(error_str) elif pids.count('\n') > 0 and str(self_pid) not in pids: # If self is not in result and the pids number is still # > 0, it means that the another glance-scrubber process is # running. sys.exit(error_str) app.revert_image_status(CONF.restore) elif CONF.daemon: server = scrubber.Daemon(CONF.wakeup_time) server.start(app) server.wait() else: app.run() except (exception.ImageNotFound, exception.Conflict) as e: sys.exit("ERROR: %s" % e) except RuntimeError as e: sys.exit("ERROR: %s" % e)