如何使用Chef Windows重新启动资源仅重新启动一次

问题描述 投票:0回答:2

我当前正在尝试在厨师资源中使用重新启动资源:

reboot 'ADS Install Complete' do
  action :nothing
  reason 'Cannot continue Chef run without a reboot.'
  only_if {reboot_pending?}
end

...

execute 'Initialize ADS Configuration INI' do
  command "\"#{node["ads-tfs-ini"]["tfsconfig_path"]}\" unattend \/create \/type:#{node["ads-tfs-ini"]["Scenario"]} \/unattendfile:\"#{node["ads-tfs-ini"]["unattend_file_path"]}\""
  only_if { ! "#{ENV['JAVA_HOME']}".to_s.empty? }
  notifies :request_reboot, 'reboot[ADS Install Complete]', :delayed
end

我正在经历一个无休止的重启循环(客户端重启-> chef客户端运行-> chef客户端重新运行run_list-client重启-> ...)。我怎样才能重启一次?

windows chef reboot
2个回答
0
投票

您可以添加一些验证以检查计算机是否已重新启动一次。

ruby_block "reboot" do
  unless File.exist?("C:\reboot") do
    block do
      Chef::Util::FileEdit.new('C:\reboot').write_file
      Chef::ShellOut.new("shutdown /r").run_command
    end
  end
end

此解决方案并不是很好,但是应该可以。重启位于ruby块内部,只有在C:\ reboot不存在的情况下才会运行。如果该文件不存在,则该块将创建该文件,然后调用重新引导。在第二次运行Chef时,该文件将存在,因此不会触发重新启动。

Here is the documention regarding ruby_block


0
投票

来自reboot主厨资源:

使用重新启动资源重新启动节点,这是某些平台上某些安装的必要步骤。支持在Microsoft Windows,macOS和Linux平台上使用此资源。

reboot
© www.soinside.com 2019 - 2024. All rights reserved.