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?