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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With