From 1c27047f4b067656b4992271539da131f792941f Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 13 Jan 2018 22:49:50 -0500 Subject: [PATCH] Remove tmpfs mount on /tmp and bring back /tmp cleanup on halt fixes #406 because the `tmpfs` mount isn't needed anymore. Careful considerations had to be taken because #68 mentions host-side data loss when cleaning up `/tmp`. We mitigate this by ensuring that all mounts under `/tmp` are unmounted before we proceed with our `rm -rf` operation. More context about this issue can be found in #360. --- lib/vagrant-lxc/action.rb | 2 ++ lib/vagrant-lxc/action/boot.rb | 3 --- .../action/remove_temporary_files.rb | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 lib/vagrant-lxc/action/remove_temporary_files.rb diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 38d08ac..ccd67b2 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -12,6 +12,7 @@ require 'vagrant-lxc/action/handle_box_metadata' require 'vagrant-lxc/action/prepare_nfs_settings' require 'vagrant-lxc/action/prepare_nfs_valid_ids' require 'vagrant-lxc/action/private_networks' +require 'vagrant-lxc/action/remove_temporary_files' require 'vagrant-lxc/action/setup_package_files' require 'vagrant-lxc/action/warn_networks' @@ -124,6 +125,7 @@ module Vagrant end b2.use ClearForwardedPorts + b2.use RemoveTemporaryFiles b2.use GcPrivateNetworkBridges b2.use Builtin::Call, Builtin::GracefulHalt, :stopped, :running do |env2, b3| if !env2[:result] diff --git a/lib/vagrant-lxc/action/boot.rb b/lib/vagrant-lxc/action/boot.rb index 08d331d..90b783f 100644 --- a/lib/vagrant-lxc/action/boot.rb +++ b/lib/vagrant-lxc/action/boot.rb @@ -26,9 +26,6 @@ module Vagrant config.customize 'mount.entry', '/sys/fs/selinux sys/fs/selinux none bind,ro 0 0' end - # Make /tmp a tmpfs to prevent init scripts from nuking synced folders mounted in here - config.customize 'mount.entry', 'tmpfs tmp tmpfs nodev,nosuid,size=2G 0 0' - env[:ui].info I18n.t("vagrant_lxc.messages.starting") env[:machine].provider.driver.start(config.customizations) diff --git a/lib/vagrant-lxc/action/remove_temporary_files.rb b/lib/vagrant-lxc/action/remove_temporary_files.rb new file mode 100644 index 0000000..9fb0cc2 --- /dev/null +++ b/lib/vagrant-lxc/action/remove_temporary_files.rb @@ -0,0 +1,23 @@ +module Vagrant + module LXC + module Action + class RemoveTemporaryFiles + def initialize(app, env) + @app = app + @logger = Log4r::Logger.new("vagrant::lxc::action::remove_tmp_files") + end + + def call(env) + @logger.debug 'Removing temporary files' + driver = env[:machine].provider.driver + # To prevent host-side data loss, it's important that all mounts under /tmp are unmounted + # before we proceed with the `rm -rf` operation. See #68 and #360. + driver.attach("findmnt -R /tmp -o TARGET --list --noheadings | xargs -L 1 --no-run-if-empty umount") + driver.attach("rm -rf /tmp/*") + + @app.call env + end + end + end + end +end