更新时间:2023-01-30 10:18:38
据我所知,如果尝试重新启动操作系统,您将无法在中断的地方执行单个脚本/命令集,例如:
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.
Vagrantfile的示例片段,以突出显示其可能的用途:
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