Fredrik
Fredrik

Reputation: 3293

Time out of sync using VirtualBox + Vagrant + Homestead

Whenever my computer sleeps, the time in the Homestead environment goes out of sync. The time doesn't update when it wakes up, it just keeps on going from when the computer started to sleep. This forces me to destroy and then up Vagrant.

Versions:

I have added this to the Vagrantfile:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.provider 'virtualbox' do |vb|
       vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000 ]
    end

    config.vm.provider "virtualbox" do |vb|
       vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
    end

    // More code...

How do I make the Homestead environment sync the time?

Upvotes: 5

Views: 3694

Answers (4)

Yevgeniy Afanasyev
Yevgeniy Afanasyev

Reputation: 41400

restart the ntp service

$sudo service ntp restart

Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks. In operation since before 1985, NTP is one of the oldest Internet protocols in current use.

Upvotes: 1

Yami Glick
Yami Glick

Reputation: 2016

I came across this solution when going out of sync with s3.

edit the ntp.conf

sudo vim /etc/ntp.conf

change the servers to:

server 0.amazon.pool.ntp.org iburst
server 1.amazon.pool.ntp.org iburst
server 2.amazon.pool.ntp.org iburst
server 3.amazon.pool.ntp.org iburst

restart the ntp service

sudo service ntp restart

and you're done.

Upvotes: 4

Hatcham
Hatcham

Reputation: 330

You can run:

sudo service ntp stop && sudo ntpdate -s time.nist.gov && sudo service ntp start

(You may need to install ntpdate)

I've added this to after.sh so it runs on provision, but it doesn't run on wake or "up".

I'd love to find a way to do that automatically.

Upvotes: 0

joepferguson
joepferguson

Reputation: 1088

When your computer sleeps it's using vagrant suspend command which is like hitting the pause button on time (and the universe) as far as the virtual machine is considered.

The only real fix is to manually vagrant halt your VMs before you let your computer sleep.

Upvotes: 0

Related Questions