Skip to content

Commit

Permalink
Prevent /tmp from filling up.
Browse files Browse the repository at this point in the history
Unexpectedly, the behaviour of amazon ami linnx instance does not
clear /tmp on reboot.

Handle in the program-space by:

 - Downloading all artefacts to a single subdir in /tmp.
 - Removing the /tmp/downloads when invoking clean-previous-state
  • Loading branch information
Matt Russell committed Jul 9, 2020
1 parent f7ac8a0 commit 8e9addc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/azanium/artefact.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
Info = collections.namedtuple('Info', ('download_dir',
'install_dir',
'version'))

DOWNLOAD_DIR = '/tmp/downloads'

def prepare(cmd_ctx, func):
f_name = func.__name__
tmpdir = tempfile.mkdtemp(suffix='-db-migration-downloads')
tmpdir = tempfile.mkdtemp(suffix='-db-migration-downloads',
dir=DOWNLOAD_DIR)
download_dir = os.path.join(tmpdir, f_name)
install_dir = cmd_ctx.path(f_name)
version = util.get_deploy_versions()[f_name]
Expand All @@ -27,7 +28,7 @@ def prepare(cmd_ctx, func):

def prepared(func):
"""Decorator providing a click command function with download/install info.
Fowards to the original function with addtional ``Info`` object
containing details such as install and download disk locations.
"""
Expand Down
3 changes: 0 additions & 3 deletions src/azanium/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def tace(context, afct, url_template=None):
local_path = downloaded[0]
with tarfile.open(local_path) as tf:
tf.extract('./tace', path=afct.install_dir)
shutil.rmtree(os.path.dirname(local_path))
tace_path = os.path.join(afct.install_dir, 'tace')
util.touch_dir(afct.install_dir)
util.make_executable(tace_path, logger)
Expand All @@ -107,7 +106,6 @@ def datomic_free(context, afct, url_template=None):
tmpdir = tempfile.mkdtemp()
with zipfile.ZipFile(util.download(url, download_path)) as zf:
zf.extractall(tmpdir)
shutil.rmtree(os.path.dirname(download_path))
shutil.rmtree(install_dir)
shutil.move(os.path.join(tmpdir, fullname), install_dir)
util.touch_dir(install_dir)
Expand Down Expand Up @@ -141,7 +139,6 @@ def pseudoace(context, afct, **kw):
tempdir = tempfile.mkdtemp()
with tarfile.open(dl_path) as tf:
tf.extractall(path=tempdir)
shutil.rmtree(os.path.dirname(dl_path))
archive_filename = os.path.split(dl_path)[-1]
fullname = archive_filename.rsplit('.', 2)[0]
tmp_src_path = os.path.join(tempdir, fullname)
Expand Down
1 change: 1 addition & 0 deletions src/azanium/runcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def backup_db(context, db_name=None):
@util.pass_command_context
def clean_previous_state(context):
to_remove = set(installers.commands) | {
artefact.DOWNLOAD_DIR,
'acedb_database',
'acedb_id_catalog',
'acedb-dump',
Expand Down

0 comments on commit 8e9addc

Please sign in to comment.