def process(args): fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is None or not phlsys_pid.is_running(pid): raise Exception("Arcyd is not running") if args.force: phlsys_pid.request_terminate(pid) else: killfile = 'var/command/killfile' phlsys_fs.write_text_file(killfile, '') if os.path.isfile(killfile): time.sleep(1) while os.path.isfile(killfile): print 'waiting for arcyd to remove killfile ..' time.sleep(1) # wait for Arcyd to not be running if phlsys_pid.is_running(pid): time.sleep(1) while phlsys_pid.is_running(pid): print 'waiting for arcyd to exit' time.sleep(1)
def stop_arcyd_pid(pid, killfile, message=''): phlsys_fs.write_text_file_atomic(killfile, message) if os.path.isfile(killfile): time.sleep(1) while os.path.isfile(killfile): print('waiting for arcyd to remove killfile ..') time.sleep(1) # wait for Arcyd to not be running if phlsys_pid.is_running(pid): time.sleep(1) while phlsys_pid.is_running(pid): print('waiting for arcyd to exit') time.sleep(1)
def process(args): fs = abdt_fs.make_default_accessor() pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): raise Exception("already running") pid = phlsys_pid.get() fs.set_pid(pid) repo_configs = _list_repo_configs_in_workingdir() # XXX: hack this horribly by delegating everything to the 'process-repos' # command parser = argparse.ArgumentParser() params = [] for line in open('config'): params.append(line.strip()) if args.no_loop: params.append('--no-loop') params.append('--repo-configs') for repo in repo_configs: params.append('@' + repo) abdcmd_processrepos.setupParser(parser) args = parser.parse_args(params) abdcmd_processrepos.process(args)
def start_arcyd(daemonize=True, loop=True, restart=False, stop_message=''): # exit gracefully if this process is killed phlsys_signal.set_exit_on_sigterm() fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): if restart: stop_arcyd_pid(pid, fs.layout.killfile, stop_message) else: raise Exception("already running") if daemonize: phlsys_daemonize.do( stdout_path=fs.layout.stdout, stderr_path=fs.layout.stderr) # important that we do this *after* daemonizing pid = phlsys_pid.get() fs.set_pid(pid) parser = argparse.ArgumentParser() params = [] for line in open(fs.layout.root_config): params.append(line.strip()) if not loop: params.append('--no-loop') repo_configs = abdi_repoargs.parse_config_file_list( fs.repo_config_path_list()) abdi_processrepos.setupParser(parser) args = parser.parse_args(params) def logger_config(): _setup_logger(fs, daemonize) with phlsys_multiprocessing.logging_context(logger_config): _LOGGER.debug("start with args: {}".format(args)) while True: _LOGGER.info("arcyd started") try: exit_code = abdi_processrepos.process(args, repo_configs) _LOGGER.debug("arcyd process loop exit_code: %s" % exit_code) if exit_code == abdi_processexitcodes.ExitCodes.ec_exit: break finally: _LOGGER.info("arcyd stopped") _LOGGER.debug("reloading arcyd configuration") try: with fs.lockfile_context(): repo_configs = abdi_repoargs.parse_config_file_list( fs.repo_config_path_list()) except phlsys_fs.LockfileExistsError: _LOGGER.error("couldn't acquire lockfile, reload failed")
def stop_arcyd_pid(pid): killfile = 'var/command/killfile' phlsys_fs.write_text_file(killfile, '') if os.path.isfile(killfile): time.sleep(1) while os.path.isfile(killfile): print('waiting for arcyd to remove killfile ..') time.sleep(1) # wait for Arcyd to not be running if phlsys_pid.is_running(pid): time.sleep(1) while phlsys_pid.is_running(pid): print('waiting for arcyd to exit') time.sleep(1)
def process(args): fs = abdt_fs.make_default_accessor() exit_code = 0 with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): raise Exception("cannot fsck whilst arcyd is running.") repo_config_path_list = _determine_repo_config_path_list( fs, args.repos) if not _check_repo_config_path_list(repo_config_path_list): exit_code = 1 repo_name_config_list = abdi_repoargs.parse_config_file_list( repo_config_path_list) if not _check_repo_name_config_list(args, repo_name_config_list): exit_code = 1 if exit_code != 0 and not args.fix: print("use '--fix' to attempt to fix the issues") return exit_code
def process(args): # exit gracefully if this process is killed phlsys_signal.set_exit_on_sigterm() fs = abdt_fs.make_default_accessor() pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): raise Exception("already running") if not args.foreground: phlsys_daemonize.do( stdout_path=fs.layout.stdout, stderr_path=fs.layout.stderr) # important that we do this *after* daemonizing pid = phlsys_pid.get() fs.set_pid(pid) parser = argparse.ArgumentParser() params = [] for line in open(fs.layout.root_config): params.append(line.strip()) if args.no_loop: params.append('--no-loop') abdi_processrepos.setupParser(parser) args = parser.parse_args(params) abdi_processrepos.process(args, fs.repo_config_path_list())
def stop_arcyd(): fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is None or not phlsys_pid.is_running(pid): raise Exception("Arcyd is not running") stop_arcyd_pid(pid)
def stop_arcyd(message=''): fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is None or not phlsys_pid.is_running(pid): raise Exception("Arcyd is not running") stop_arcyd_pid(pid, fs.layout.killfile, message)
def reload_arcyd(): fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is None or not phlsys_pid.is_running(pid): raise Exception("Arcyd is not running") phlsys_fs.write_text_file('var/command/reload', '')
def process(args): _ = args # NOQA fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): raise Exception("cannot fetch whilst arcyd is running.") repo_config_path_list = fs.repo_config_path_list() repo_name_config_list = abdi_repoargs.parse_config_file_list( repo_config_path_list) url_watcher_wrapper = phlurl_watcher.FileCacheWatcherWrapper( fs.layout.urlwatcher_cache_path) # Let the user know what's happening before potentially blocking for a # while. print('Refreshing repository snoop status ..', end=' ') # Make sure that the output is actually visible by flushing stdout # XXX: Will use 'flush' parameter to 'print()' in Python 3.3 sys.stdout.flush() print("done") url_watcher_wrapper.watcher.refresh() for repo_name, repo_config in repo_name_config_list: print(repo_name + ' ..', end=' ') # Make sure that the output is actually visible by flushing stdout # XXX: Will use 'flush' parameter to 'print()' in Python 3.3 sys.stdout.flush() snoop_url = abdi_repoargs.get_repo_snoop_url(repo_config) sys_repo = phlsys_git.Repo(repo_config.repo_path) refcache_repo = phlgitx_refcache.Repo(sys_repo) differ_cache = abdt_differresultcache.Cache(refcache_repo) abd_repo = abdt_git.Repo( refcache_repo, differ_cache, "origin", repo_config.repo_desc) did_fetch = abdi_processrepoarglist.fetch_if_needed( url_watcher_wrapper.watcher, snoop_url, abd_repo, repo_config.repo_desc) if did_fetch: print('fetched') else: print('skipped') url_watcher_wrapper.save()
def process(args): _ = args # NOQA fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): raise Exception("cannot fetch whilst arcyd is running.") repo_config_path_list = fs.repo_config_path_list() repo_name_config_list = abdi_repoargs.parse_config_file_list( repo_config_path_list) url_watcher_wrapper = phlurl_watcher.FileCacheWatcherWrapper( fs.layout.urlwatcher_cache_path) # Let the user know what's happening before potentially blocking for a # while. print('Refreshing repository snoop status ..', end=' ') # Make sure that the output is actually visible by flushing stdout # XXX: Will use 'flush' parameter to 'print()' in Python 3.3 sys.stdout.flush() print("done") url_watcher_wrapper.watcher.refresh() for repo_name, repo_config in repo_name_config_list: print(repo_name + ' ..', end=' ') # Make sure that the output is actually visible by flushing stdout # XXX: Will use 'flush' parameter to 'print()' in Python 3.3 sys.stdout.flush() snoop_url = abdi_repoargs.get_repo_snoop_url(repo_config) sys_repo = phlsys_git.Repo(repo_config.repo_path) refcache_repo = phlgitx_refcache.Repo(sys_repo) differ_cache = abdt_differresultcache.Cache(refcache_repo) abd_repo = abdt_git.Repo(refcache_repo, differ_cache, "origin", repo_config.repo_desc) did_fetch = abdi_processrepoarglist.fetch_if_needed( url_watcher_wrapper.watcher, snoop_url, abd_repo, repo_config.repo_desc) if did_fetch: print('fetched') else: print('skipped') url_watcher_wrapper.save()
def process(args): fs = abdt_fs.make_default_accessor() pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): raise Exception("cannot remove repo whilst arcyd is running.") repo_name = args.name os.remove(fs.layout.repo_config(repo_name)) os.remove(fs.layout.repo_try(repo_name)) os.remove(fs.layout.repo_ok(repo_name)) shutil.rmtree(fs.layout.repo(repo_name))
def start_arcyd(daemonize=True, loop=True, restart=False): # exit gracefully if this process is killed phlsys_signal.set_exit_on_sigterm() fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): if restart: stop_arcyd_pid(pid) else: raise Exception("already running") if daemonize: phlsys_daemonize.do( stdout_path=fs.layout.stdout, stderr_path=fs.layout.stderr) # important that we do this *after* daemonizing pid = phlsys_pid.get() fs.set_pid(pid) parser = argparse.ArgumentParser() params = [] for line in open(fs.layout.root_config): params.append(line.strip()) if not loop: params.append('--no-loop') repo_configs = abdi_repoargs.parse_config_file_list( fs.repo_config_path_list()) abdi_processrepos.setupParser(parser) args = parser.parse_args(params) def logger_config(): _setup_logger(fs) with phlsys_multiprocessing.logging_context(logger_config): _LOGGER.debug("start with args: {}".format(args)) _LOGGER.info("arcyd started") try: abdi_processrepos.process(args, repo_configs) finally: _LOGGER.info("arcyd stopped")
def process(args): # exit gracefully if this process is killed phlsys_signal.set_exit_on_sigterm() fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): raise Exception("already running") if not args.foreground: phlsys_daemonize.do( stdout_path=fs.layout.stdout, stderr_path=fs.layout.stderr) # important that we do this *after* daemonizing pid = phlsys_pid.get() fs.set_pid(pid) parser = argparse.ArgumentParser() params = [] for line in open(fs.layout.root_config): params.append(line.strip()) if args.no_loop: params.append('--no-loop') repo_configs = abdi_repoargs.parse_config_file_list( fs.repo_config_path_list()) abdi_processrepos.setupParser(parser) args = parser.parse_args(params) # setup to log everything to fs.layout.log_info, with a timestamp logging.Formatter.converter = time.gmtime logging.basicConfig( format='%(asctime)s UTC: %(levelname)s: %(message)s', level=logging.INFO, filename=fs.layout.log_info) _LOGGER.info("arcyd started") try: abdi_processrepos.process(args, repo_configs) finally: _LOGGER.info("arcyd stopped")
def process(args): fs = abdt_fs.make_default_accessor() with fs.lockfile_context(): pid = fs.get_pid_or_none() if pid is not None and phlsys_pid.is_running(pid): raise Exception("cannot remove repo whilst arcyd is running.") repo_name = args.name if args.lookup_url: repo_name = _determine_name_from_url(fs, repo_name) _remove_file_ignore_fail(fs.layout.repo_try(repo_name)) _remove_file_ignore_fail(fs.layout.repo_ok(repo_name)) _remove_dir_ignore_fail(fs.layout.repo(repo_name)) fs.remove_repo_config(repo_name)