Beispiel #1
0
def unmount_tmpfs(site: SiteContext,
                  output: bool = True,
                  kill: bool = False) -> bool:
    # During omd update TMPFS hook might not be set so assume
    # that the hook is enabled by default.
    # If kill is True, then we do an fuser -k on the tmp
    # directory first.

    # For some files in tmpfs we want the IO performance of the tmpfs and
    # want to keep the files between unmount / mount operations (if possible).
    if os.path.exists(site.tmp_dir):
        if output:
            sys.stdout.write("Saving temporary filesystem contents...")
        save_tmpfs_dump(site)
        if output:
            ok()

    # Clear directory hierarchy when not using a tmpfs
    if not tmpfs_mounted(site.name) or _tmpfs_is_managed_by_node(site):
        tmp = site.tmp_dir
        if os.path.exists(tmp):
            if output:
                sys.stdout.write("Cleaning up tmp directory...")
                sys.stdout.flush()
            delete_directory_contents(tmp)
            if output:
                ok()
        return True

    if output:
        sys.stdout.write("Unmounting temporary filesystem...")

    for _t in range(0, 10):
        if not tmpfs_mounted(site.name):
            if output:
                ok()
            return True

        if _unmount(site):
            if output:
                ok()
            return True

        if kill:
            if output:
                sys.stdout.write("Killing processes still using '%s'\n" %
                                 site.tmp_dir)
            subprocess.call(["fuser", "--silent", "-k", site.tmp_dir])

        if output:
            sys.stdout.write(kill and "K" or ".")
            sys.stdout.flush()
        time.sleep(1)

    if output:
        raise SystemExit(tty.error + ": Cannot unmount temporary filesystem.")

    return False
Beispiel #2
0
 def unmount(site):
     delete_directory_contents(site.tmp_dir)
     fake_tmpfs.unmount()