是否可以在使用Vagrant配置计算机时重新启动计算机,并在脚本停止的情况下启动?

lee*_*d00 18 bash vagrant vagrant-provision

我正在阅读bash中的一个教程,他们说要重启机器,没有选择直接重启服务,这是重启机器的问题,然后还有更多的命令,在配置后仍然需要运行.

那么有什么方法可以在配置中重新启动一个盒子然后在你之后离开的地方拿起它?

jax*_*xim 19

据我所知,如果尝试重新启动操作系统,则不能使用单个脚本/命令集来执行它停止的位置,例如:

  config.vm.provision "shell", inline: <<-SHELL
    echo $(date) > ~/rebootexample
    reboot
    echo $(date) >> ~/rebootexample
  SHELL
Run Code Online (Sandbox Code Playgroud)

在此示例中,将不执行第二个回声调用.

您可以拆分脚本/命令并使用插件,例如vagrant reload.

Vagrantfile的一个示例片段,用于突出显示其可能的用途:

  # 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
Run Code Online (Sandbox Code Playgroud)