I use Vagrant to host a stateless service on a server. When the server starts, I want my service to start as well, so I wrote a script called by /etc/rc.local
that restores a working snapshot of the service.
In /etc/rc.local
:
sudo -u myservice /myservice/start.sh || true
/myservice/start.sh
:
#!/usr/bin/env bash
cd "/myservice"
vagrant snapshot restore fresh
Sometimes, however, after rebooting my service is not available because the restore fails. If I try to restore the snapshot manually, I get the following error message. What is the meaning of such error? Aren’t snapshots designed to survive a reboot?
Some issue reports suggest to recreate the snapshot from scratch, which works but is not something that I can do at every reboot.
...
==> myservice-3: Discarding saved state of VM...
==> myservice-3: Restoring the snapshot 'fresh'...
==> myservice-3: Checking if box 'ubuntu/focal64' version '20221025.0.0' is up to date...
==> myservice-3: Resuming suspended VM...
==> myservice-3: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["startvm", "f4deba11-9511-4049-a0ab-07f0e4db09de", "--type", "headless"]
Stderr: VBoxManage: error: lsilogicscsi#0: Target 0 config mismatch: config=false state=true [ver=5 pass=final] (VERR_SSM_LOAD_CONFIG_MISMATCH)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole
My Vagrantfile
:
# -*- mode: ruby -*-
# vi: set ft=ruby :
require "getoptlong"
# Read command line parameters
options = GetoptLong.new(
[ "--token", GetoptLong::OPTIONAL_ARGUMENT ],
)
options.ordering = GetoptLong::REQUIRE_ORDER
token = "undefined"
options.each do |opt, arg|
case opt
when "--token"
token = arg
end
end
# Set the number of runners to start
num_runners = 10
# Configure multiple machines
Vagrant.configure("2") do |config|
1.upto(num_runners) do |runner_id|
runner_name = "myservice-#{runner_id}"
config.vm.define runner_name do |node|
# Set hostname
node.vm.hostname = runner_name
# Set OS
node.vm.box = "ubuntu/focal64"
# Configure VM resource limits
node.vm.provider "virtualbox" do |vb|
vb.memory = 8192
vb.cpus = 4
end
# Install Docker
node.vm.provision :docker
# Prepare GitHub runner
node.vm.provision :shell, name: "Install service", privileged: false, inline: <<-SHELL
# Install the service, storing the token.
# ...
SHELL
node.vm.provision :shell, name: "Start service", inline: <<-SHELL
# Start the service
# ...
SHELL
end
end
end
Vagrant version: 2.3.4
OS: Ubuntu 20.04.5 LTS (Focal Fossa)