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.
This commit is contained in:
Brian C. Lane 2018-05-10 10:58:43 -07:00
parent 3a38a57ae1
commit 9978503a69
3 changed files with 9 additions and 2 deletions

View File

@ -48,6 +48,7 @@ def configure(conf_file="/etc/lorax/composer.conf", root_dir="/", test_config=Fa
conf.set("composer", "yum_root", os.path.realpath(joinpaths(root_dir, "/var/tmp/composer/yum/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")

View File

@ -47,7 +47,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()
@ -169,7 +170,7 @@ def make_compose(cfg, results_dir):
cfg_dict["squashfs_args"] = None
cfg_dict["lorax_templates"] = cfg.share_dir
cfg_dict["tmp"] = "/var/tmp/"
cfg_dict["tmp"] = cfg.tmp
cfg_dict["dracut_args"] = None # Use default args for dracut
# Compose things in a temporary directory inside the results directory
@ -206,6 +207,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

View File

@ -210,6 +210,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):