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

后端 未结 4 2175
北荒
北荒 2021-02-12 11:47

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 t

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-12 12:29

    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
    

提交回复
热议问题