问题描述
我正在bash上阅读教程,他们说要重启机器,没有选择直接重启服务的问题,这是重启机器的问题,之后还有更多命令需要在配置时运行.
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?
推荐答案
据我所知,如果尝试重新启动操作系统,您将无法在中断的地方执行单个脚本/命令集,例如:
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
这篇关于在使用Vagrant并从脚本停止的地方开始配置计算机时,是否可以重新启动计算机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!