From 12cb2736ac5d7aeb3d3b14ed0c0319293be70981 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 10 May 2018 10:58:43 -0700 Subject: [PATCH] Pass the --tmp value into run_creator and cleanup after a crash Crashing can sometimes leave directories in /var/tmp/lmc-* so clean those up after run_creator is finished. --- src/pylorax/api/config.py | 1 + src/pylorax/api/queue.py | 9 +++++++-- src/pylorax/creator.py | 1 - src/sbin/lorax-composer | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pylorax/api/config.py b/src/pylorax/api/config.py index a27be4dd..cdac49a1 100644 --- a/src/pylorax/api/config.py +++ b/src/pylorax/api/config.py @@ -48,6 +48,7 @@ def configure(conf_file="/etc/lorax/composer.conf", root_dir="/", test_config=Fa conf.set("composer", "dnf_root", os.path.realpath(joinpaths(root_dir, "/var/tmp/composer/dnf/root/"))) conf.set("composer", "repo_dir", os.path.realpath(joinpaths(root_dir, "/var/tmp/composer/repos.d/"))) conf.set("composer", "cache_dir", os.path.realpath(joinpaths(root_dir, "/var/tmp/composer/cache/"))) + conf.set("composer", "tmp", os.path.realpath(joinpaths(root_dir, "/var/tmp/"))) conf.add_section("users") conf.set("users", "root", "1") diff --git a/src/pylorax/api/queue.py b/src/pylorax/api/queue.py index 993ff32e..565d57a6 100644 --- a/src/pylorax/api/queue.py +++ b/src/pylorax/api/queue.py @@ -48,7 +48,8 @@ def start_queue_monitor(cfg, uid, gid): """ lib_dir = cfg.get("composer", "lib_dir") share_dir = cfg.get("composer", "share_dir") - monitor_cfg = DataHolder(composer_dir=lib_dir, share_dir=share_dir, uid=uid, gid=gid) + tmp = cfg.get("composer", "tmp") + monitor_cfg = DataHolder(composer_dir=lib_dir, share_dir=share_dir, uid=uid, gid=gid, tmp=tmp) p = mp.Process(target=monitor, args=(monitor_cfg,)) p.daemon = True p.start() @@ -170,7 +171,7 @@ def make_compose(cfg, results_dir): cfg_dict["squashfs_args"] = None cfg_dict["lorax_templates"] = find_templates(cfg.share_dir) - cfg_dict["tmp"] = "/var/tmp/" + cfg_dict["tmp"] = cfg.tmp cfg_dict["dracut_args"] = None # Use default args for dracut # TODO How to support other arches? @@ -210,6 +211,10 @@ def make_compose(cfg, results_dir): # Extract the results of the compose into results_dir and cleanup the compose directory move_compose_results(install_cfg, results_dir) finally: + # Make sure any remaining temporary directories are removed (eg. if there was an exception) + for d in glob(joinpaths(cfg.tmp, "lmc-*")): + shutil.rmtree(d) + # Make sure that everything under the results directory is owned by the user user = pwd.getpwuid(cfg.uid).pw_name group = grp.getgrgid(cfg.gid).gr_name diff --git a/src/pylorax/creator.py b/src/pylorax/creator.py index 6ef781f0..e22d5321 100644 --- a/src/pylorax/creator.py +++ b/src/pylorax/creator.py @@ -712,4 +712,3 @@ def run_creator(opts, callback_func=None): result_dir = None return (result_dir, disk_img) - diff --git a/src/sbin/lorax-composer b/src/sbin/lorax-composer index 524a1b5b..e5e22a7c 100755 --- a/src/sbin/lorax-composer +++ b/src/sbin/lorax-composer @@ -214,6 +214,7 @@ if __name__ == '__main__': sys.exit(1) server.config["COMPOSER_CFG"] = configure(conf_file=opts.config) + server.config["COMPOSER_CFG"].set("composer", "tmp", opts.tmp) # Make sure the git repo can be accessed by the API uid/gid if os.path.exists(opts.BLUEPRINTS):