Score:0

Trigger NTP restart after `vagrant resume`

ad flag
kol

I manage some Debian 11 server VMs using Vagrant. Sometimes I need to vagrant suspend them, and I noticed that after vagrant resume, their system time is off. Running systemctl status ntp shows the NTP service is turned off by a failure. I could solve this by restarting NTP manually after vagrant resume, so I wanted to add a trigger to the Vagrantfile:

config.trigger.after :resume do |trigger|
  trigger.info = "Restart NTP"
  trigger.run = {inline: "bash -c 'systemctl start ntp'"}
end

...but now vagrant resume throws an error:

==> xxx-vm: Running action triggers after resume ...
==> xxx-vm: Running trigger...
==> xxx-vm: Restart NTP
    xxx-vm: Running local: Inline script
    xxx-vm: bash -c 'systemctl start ntp'
    xxx-vm: System has not been booted with systemd as init system (PID 1). Can't operate.
    xxx-vm: Failed to connect to bus: Host is down
==> xxx-vm: Trigger run failed

I thought this trigger should run after resuming the VM, but apparently the VM is still down when it runs. Is it possible to run a script automatically when a VM is resumed and running?

Score:0
ad flag
kol

I figured it out: run runs a script on the host, to run it on the guest (the VM), run_remote has to be used:

config.trigger.after :resume do |trigger|
  trigger.info = "Restart NTP"
  trigger.run_remote = {inline: "bash -c 'systemctl start ntp'"}
end
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.