gpt4 book ai didi

vagrant - 是否可以在 vagrant halt/suspend 之前添加 Action Hook

转载 作者:行者123 更新时间:2023-12-05 03:11:52 25 4
gpt4 key购买 nike

我想在挂起或停止操作生效之前触发我的 VM 上的操作。

我看到可以使用的操作 Hook ,但它们都是操作完成后才使用的https://www.vagrantup.com/docs/plugins/action-hooks.html .有什么线索吗?

最佳答案

我相信这些钩子(Hook)中的大部分都是用于插件开发的——你正在看的是 vagrant trigger plugin所以如果你想在暂停或停止之前完成操作:

Vagrant.configure("2") do |config|
# Your existing Vagrant configuration
...

# run some script before the guest is halted
config.trigger.before :halt do
info "Dumping the database before destroying the VM..."
run_remote "bash /vagrant/cleanup.sh"
end

# run some script before the guest is suspended
config.trigger.before :suspend do
info "Dumping the database before destroying the VM..."
run_remote "bash /vagrant/cleanup.sh"
end

# clean up files on the host after the guest is destroyed
config.trigger.after :destroy do
run "rm -Rf tmp/*"
end

# start apache on the guest after the guest starts
config.trigger.after :up do
run_remote "service apache2 start"
end

end

关于vagrant - 是否可以在 vagrant halt/suspend 之前添加 Action Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35912776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com