Chef-如何重新启动VM并继续执行操作 [英] Chef - How Reboot VM and continue performing actions
本文介绍了Chef-如何重新启动VM并继续执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在厨师食谱中,我需要在执行某些操作
之后在节点上执行重新引导,并且在完成重新引导之后,我需要继续执行其他操作:
In a Chef recipe, I need to perform a reboot on a Node after doing some actions, and after the reboot is done, I need to continue doing another actions:
配方:
-动作1
-动作2
-重新启动
-action3
-action4...。
Recipe: -action 1 -action 2 -reboot -action3 -action4....
我检查了社区中一些现有的食谱:重新启动处理程序,chef-reboot,chef-restart,chef-dominous,但是我无法使它们中的任何一个起作用。
I have checked some existing cookbook in the community: reboot-handler, chef-reboot, chef-restart, chef-dominous, but I cannot make any of them work.
Chef中是否有某种方法可以得到我需要的东西?
请提供详细的示例。
Is there some method in Chef to get what I need? Please provide detailed examples.
非常感谢您的帮助。
推荐答案
This is a recipe of mine you can try.
# Cookbook Name:: reboot-test
# Recipe:: default
bash 'reboot' do
cwd '/tmp'
code <<-EOH
touch reboot.lock
chmod +x /etc/rc.d/rc.local
# echo "/usr/local/bin/chef-client" >> /etc/rc.d/rc.local
cp /etc/rc.d/rc.local /etc/rc.d/rc.local_bkp
echo "/bin/chef-client" >> /etc/rc.d/rc.local
reboot
EOH
ignore_failure true
not_if do ::File.exists?('/tmp/reboot.lock') end
not_if 'ls -lrth /tmp/reboot.lock'
end
#This is where you need to code for the config automation like the execute #resource but before the bash resource "CHEF-CLIENT-#EXIT"
execute 'touch' do
command '/bin/touch /tmp/suman.test'
end
bash 'chef_client_exit' do
code <<-EOH
rm -rf /tmp/reboot.lock
# sed -i '/\/usr\/local\/bin\/chef-client/d' /etc/rc.d/rc.local
# sed -e '/^\/bin\/chef-client/d' -i /etc/rc.d/rc.local
# sed -e '\|^/bin/chef-client|d' -i /etc/rc.d/rc.local
cp /etc/rc.d/rc.local_bkp /etc/rc.d/rc.local
rm -rf /etc/rc.d/rc.local_bkp
EOH
only_if 'grep -i chef-client /etc/rc.d/rc.local'
end
这篇关于Chef-如何重新启动VM并继续执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文