我正在阅读一个关于Bash的教程,其中说要重启机器,没有直接重启服务的选项,重启机器后还需要运行更多的命令进行配置。那么在云服务部署过程中是否有办法重启服务器并在之后继续完成配置呢?
我正在阅读一个关于Bash的教程,其中说要重启机器,没有直接重启服务的选项,重启机器后还需要运行更多的命令进行配置。那么在云服务部署过程中是否有办法重启服务器并在之后继续完成配置呢?
config.vm.provision "shell", inline: <<-SHELL
echo $(date) > ~/rebootexample
reboot
echo $(date) >> ~/rebootexample
SHELL
# 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
config.vm.provision 'shell', reboot: true
。然后您将会在 vagrant up
的安装输出中看到 ==> proxmox: Waiting for machine to reboot...
。问题解决了。如果可能的话,应该通过编辑将此内容添加到答案中。但编辑队列已经满了。 - Utkonosvagrant plugin install vagrant-reload
来执行#trigger reload步骤。 - Joshit您可以使用的一个技巧是发送重新启动信号并将其余的配置工作保存为脚本以在启动时运行:
config.vm.provision "shell", inline: <<-SHELL
echo "Do your thing... DONE"
cat <<-RCLOCAL | sed -s 's_^ __' > /etc/rc.local
#!/bin/bash
echo "This will be run once on next boot and then it's destroyed and never run again"
rm /etc/rc.local
RCLOCAL
chmod o+x /etc/rc.local
shutdown -r now #restart
SHELL
config.vm.provision "shell", inline: "shutdown -r now"
config.vm.provision "shell", inline: "echo 'hello world'"
results in ==>
The SSH connection was unexpectedly closed by the remote end. This
usually indicates that SSH within the guest machine was unable to
properly start up. Please boot the VM in GUI mode to check whether
it is booting properly.
可以这样做:
config.vm.provision 'shell', path: 'part1.sh'
config.vm.provision 'shell', reboot: true
config.vm.provision 'shell', path: 'part2.sh'
https://developer.hashicorp.com/vagrant/docs/provisioning/shell#reboot
Vagrant提供了一个重新启动选项进行配置,但是当前Linux不支持重新启动客户端的功能。
您可以在这里检查我的插件https://github.com/secret104278/vagrant_reboot_linux/tree/master,我已经实现了Linux重新启动的功能。