Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to restart a machine when provisioning a machine using Vagrant and pickup where the script left off?

Tags:

I was reading a tutorial in bash where they said to restart the machine, there was no option to restart a service directly, it was a matter of restarting the machine, and then there were more commands after that that still needed to be run when provisioning.

So is there any way to restart a box amid provisioning and then pick up where you left off after that?

like image 941
leeand00 Avatar asked Jan 20 '16 21:01

leeand00


People also ask

How do I restart my vagrant VM?

Command: vagrant reload [name|id] After making any modifications to the Vagrantfile, a reload should be called. The configured provisioners will not run again, by default. You can force the provisioners to re-run by specifying the --provision flag.

What does vagrant provision do?

Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process. This is useful since boxes typically are not built perfectly for your use case.

What is the provision that used in vagrant by default?

By default, provisioners are only run once, during the first vagrant up since the last vagrant destroy , unless the --provision flag is set, as noted above.

Which of following can be used as Provisioner with vagrant?

5) What is Provisioner in Vagrant? A) A provisioner is a tool to set up the virtual environment, and can be as simple as a shell script, but alternatively a more advanced tool like Chef, Puppet, or Ansible can be used.


1 Answers

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 
like image 156
jaxim Avatar answered Sep 28 '22 01:09

jaxim