Is it possible to restart a machine when provisioning a machine using Vagrant and pickup where the script left off?
As far as I know you can't have a single script/set of commands that would carry on where it left off if it attempts to restart the OS, such as:
config.vm.provision "shell", inline: <<-SHELL
echo $(date) > ~/rebootexample
reboot
echo $(date) >> ~/rebootexample
SHELL
In this example the second echo call would not be carried out.
You could split the script/commands up and use a plugin such as vagrant reload.
An example snippet of a Vagrantfile to highlight its possible use:
# execute code before reload
config.vm.provision "shell", inline: <<-SHELL
echo $(date) > ~/rebootexample
SHELL
# trigger reload
config.vm.provision :reload
# execute code after reload
config.vm.provision "shell", inline: <<-SHELL
echo $(date) >> ~/rebootexample
SHELL
I've never done this, but if I had to I would split the script into two pieces, one before restart that includes the restart command, then another that's post install.
The first one would also create a lock file.
The overall script would run the first script if the lock file didn't exist or run the second one if the file exists. This overall script would be set up for startup.