hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.15k stars 4.42k forks source link

Is possible that vagrant delete project folder? #10977

Closed MiroslawKmiec closed 5 years ago

MiroslawKmiec commented 5 years ago

Vagrant version

2.2.4

Host operating system

Win 10 Pro 64-bit, cpu i7, 16GB ram, ssd sata III

Guest operating system

Debian stretch

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'json'

# Specify Vagrant version and Vagrant API version
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"

## Declare config.json file path
configJsonPath = File.expand_path("config.json")

# Create and configure the VM(s)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

    ## Check if config file exists and load it into settings variable
    if File.exist? configJsonPath then
        settings = JSON::parse(File.read(configJsonPath))
    else
        abort "Project config file not found in " + File.dirname(__FILE__)
    end

   # Assign a friendly name to this host VM - try to change this for each project
  config.vm.hostname = settings['hostname']

  # Assign an IP inside our private network by DHCP
  config.vm.network "private_network", ip: settings['ip']

  # Fix rsync windows problem "rsync could not be found on your PATH
  # by overriding the default value from debian/jessie64
  config.vm.synced_folder ".", "/vagrant", type: "nfs"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  #config.vm.synced_folder "./data", "/var/www"
  #config.vm.synced_folder "./data", "/var/www", type: "virtualbox"
  # Enable NFS to speed up I/O performance in shared directory
  # ! on windows additional vagrant "vagrant-winnfsd" plugin is needed 
  # ! AND installed guest additions ,so install them before activating nfs
  config.vm.synced_folder "./data", "/var/www", type: "nfs"
  config.vm.synced_folder settings['fileadmin'], "/var/www/htdocs/fileadmin", type: "nfs"
  config.vm.synced_folder settings['uploads'], "/var/www/htdocs/uploads", type: "nfs"

  # Skip checking for an updated Vagrant box
  config.vm.box_check_update = false

  # Always use Vagrant's default insecure key
  config.ssh.insert_key = false

  # Spin up a "host box" 
  config.vm.box = settings['box']
  config.vm.box_url = settings['box_url']

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = false

    # Assign a friendly name to this host VM - try to change this for each project
    vb.name = settings['hostname']

    # Customize the amount of memory on the VM:
    vb.memory = settings['memory']

    # set 1 CPUs since more cpus actually decrese VM performance (read somewhere and tested: symfony app rendering time 2s vs. 400 ms!)
    vb.customize ['modifyvm', :id, '--cpus', 1]
    # IO PIC should be on for 64bit guests
    vb.customize ['modifyvm', :id, '--ioapic', 'on']
    #vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
    #vb.customize ['modifyvm', :id, '--nictype1', 'virtio']
    #vb.customize ['modifyvm', :id, '--nictype2', 'virtio'] 

    # enable symbolic links inside VM
    vb.customize ['setextradata', :id, 'VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant', '1']

    # config winnfsd if used (see shared folder on windows)
    config.winnfsd.logging = 'on'
    #config.winnfsd.uid = 1
    #config.winnfsd.gid = 1

  end

  config.vm.provision "fix-no-tty", type: "shell" do |s|
    s.privileged = false
    s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
  end

  # Enable provisioning with docker
  config.vm.provision "docker"

  # Enable provisioning with a shell script.
  # Execute first preparation steps to compile guest additions into kernel
  # see https://virtualboxes.org/doc/installing-guest-additions-on-debian/
  config.vm.provision "shell", inline: <<-SHELL
    #sudo apt-get install make
     #sudo apt-get update
     #sudo apt-get install -y build-essential module-assistant linux-headers-`uname -r` dkms
     #sudo m-a prepare --non-inter
  SHELL

  # Install docker-compose
  config.vm.provision "shell", inline: <<-SHELL
     sudo curl -sL https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
     sudo chmod +x /usr/local/bin/docker-compose
  SHELL

  config.vm.provision "shell", run: "always", inline: <<-SHELL
        echo "Starting docker containers..."
        cd /var/www/htdocs/_docker/
        #make build-php-base
        make start-dev
  SHELL

end

Debug output

Expected behavior

"vagrant halt" should close normaly.

Actual behavior

Randomly after "vagrant halt" whole dierctory is deleted (including Vagrantfile, .vagrant, and data). Virtual boxes and shared folders remains. I observed that twice. On second monitor I had opened file manager so I think that is problem with vagrant (hardware problem I think is not issue). Antyvirus scan with Bitdefender and Malwarebytes nothing found. SSD SMART informations are ok. With new version 2.2.5 not tested yet.

briancain commented 5 years ago

Hi @MirekKmiec - Do you have a debug log showing this behavior with vagrant halt --debug? Generally, Vagrant shouldn't be deleting any folders. When you run the vagrant halt command, Vagrant simply calls out to your guests capability definition for halt, which in most linux case is just running the command shutdown on the guest. Maybe the Vagrant box you are using has a trigger to delete the current working dir, but I doubt it :thinking: Anyway without a debug log it is hard to know what happened so giving us that with the delete behavior would be a good start. Thanks!

briancain commented 5 years ago

Hey there,

I am going to close this due to lack of response. If this is still occurring, please open a new issue and follow the provided issue template that appears when you click the "New Issue" button. This will help us in getting a reproduction and fix. Thanks!

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.