vagrant icon indicating copy to clipboard operation
vagrant copied to clipboard

Vagrant Freezes in 10 minutes in Mac OS Montery

Open thirusvga opened this issue 2 years ago • 6 comments

Vagrant version

Vagrant 2.214 to 2.2.19

Host operating system

MAC Monterey 12.2.1

Guest operating system

Ubuntu 18.04 and Ubuntu 20.04

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :
username = File.readlines("#{Dir.pwd}/.username").first.strip #get the developers username from the host mac custom config file
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip #get the current users pub key from the host mac

Vagrant.configure(2) do |config|

    config.nfs.map_uid = Process.uid
    config.nfs.map_gid = Process.gid

    config.ssh.forward_agent = true

    # Virtual box config
    config.vm.provider "virtualbox" do |vb, override|
        host = RbConfig::CONFIG['host_os']

        # Give VM 1/4 system memory & access to all cpu cores on the host
        # previously setting was "3048"
        if host =~ /darwin/
            cpus = `sysctl -n hw.ncpu`.to_i
            # sysctl returns Bytes and we need to convert to MB
            mem = 4096
        elsif host =~ /linux/
            cpus = `nproc`.to_i
            # meminfo shows KB and we need to convert to MB
            mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 3
        else # sorry Windows folks, I can't help you
            cpus = 2
            mem = 3024
        end

        # after some testing I found that having more than 4 cpus decreased performance
        if cpus > 4
            cpus = 4
        end

        vb.gui = false
        vb.customize ["modifyvm", :id, "--memory", mem]
        vb.customize ["modifyvm", :id, "--cpus", cpus]
        vb.customize ["modifyvm", :id, "--cpuexecutioncap", "100"]
        vb.customize ["modifyvm", :id, "--name", "magento2-devbox-pci"]
        override.vm.box = "bento/ubuntu-18.04"
        override.vm.box_version = "202105.25.0"
        override.vm.hostname = "local"
        override.vm.network "private_network", ip: "192.168.33.99"

        if host =~ /linux/ # The NFS tuning below breaks 'vagrant up' so keep using old method

            override.vm.network "forwarded_port", guest: 3306, host: 3306 # forward default mysql port
            override.vm.synced_folder "../", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=775"] }
        else

            # override.vm.network "forwarded_port", guest: 3306, host: 3306 # forward default mysql port

            # The NFS settings have been tuned to maximise performance
            # To test performance run this command when ssh'ed into the vagrant:-
                # dd if=/dev/zero of=/var/www/test bs=1M count=100
            # Take note of MB/s
            override.vm.synced_folder "../", "/var/www",
                nfs: true,
                mount_options: ["rw", "vers=3", "tcp"],
                linux__nfs_options: ["rw", "no_subtree_check", "insecure", "all_squash", "async", "noacl"]

        end
config.vm.synced_folder ".", "/vagrant", owner: "#{username}", group: "#{username}" #set owner of vagrant folder to custom dev user

    end



config.vm.provision "file", source: "#{Dir.home}/.ssh/id_rsa", destination: "/home/vagrant/.ssh/id_rsa" #copy host mac priv key to vagrant user - needed later in vm-SETUP script that runs inside vagrant
config.vm.provision 'shell', inline: "echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys", privileged: false #import into vagrant authorized_keys host pub key
config.vm.provision 'shell', inline: "echo #{ssh_pub_key} >> /home/vagrant/.ssh/id_rsa.pub", privileged: false #import into vagrant id_rsa.pub
config.vm.provision "shell", inline: "/vagrant/local.sh vm:setup" # this does all the magic on the first run of the new vagrant box

config.ssh.private_key_path = "#{Dir.home}/.ssh/id_rsa" #use the mac host pub/private key to log into vagrant - THIS IS ADDED BY VM-SETUP
config.ssh.username = "#{username}" #log into the vm using the custom username - THIS IS ADDED BY VM-SETUP
end

Debug output

After 10 mins of idle time, Vagrant is freezed and we are running the "vagrant reload" command to go to VM. Running vagrant reload in 10 mins once is very hectic jobs and required the native solutions.

Expected behavior

Vagrant should not be freezed in 10 mins. Atleast vagrant has to be run 8 hours in a day with out freeze.

Actual behavior

After 10 mins of idle time, Vagrant is freezed and (/var/www) folder not working. we are running the "vagrant reload" command to go to VM again.

Steps to reproduce

N/A

References

N/A

thirusvga avatar Apr 28 '22 07:04 thirusvga

Team, Looking for the positive reply.

thirusvga avatar May 02 '22 05:05 thirusvga

I have this issue as well. I dont think its specific to the Guest OS

jonnyeom avatar May 06 '22 13:05 jonnyeom

Same issue here

carsonweber avatar Jun 30 '22 21:06 carsonweber

Hi there,

Is this issue encountered when connected to the guest after running vagrant ssh ?

chrisroberts avatar Jul 13 '22 02:07 chrisroberts

Not always but when the hanging happens

  • my web server in the machine will stop running
  • if I vagrant ssh, it will out put the first few lines that normally output when you run the command but suddenly stop in the middle. Or, it ssh's correctly but the terminal output will freeze mid command or mid execution.

If I restart my computer, it goes back to normal, but for only a few hours perhaps.

jonnyeom avatar Jul 13 '22 07:07 jonnyeom

The same case is with me also. System configuration as:

  • Vagrant : 2.2.16
  • VBox : 6.1.32
  • OS : MacOS Monterey 12.4

Once the webserver and vagrant ssh hanged, I need to close the machine from VBoX and run vagrant up, after vagrant up it's up and running for a few mins.

System restarts also same with vagrant up.

vishalnigam111 avatar Aug 22 '22 14:08 vishalnigam111

Hi there,

It looks like this has been resolved within a previously shipped version of Vagrant so I am now closing this issue. If the original issue was not fully resolved, please reopen this issue or create a new one.

Cheers!

soapy1 avatar Jan 13 '23 23:01 soapy1