简体   繁体   English

重新启动后(Windows),厨师食谱是否可以继续?

[英]Is there a way for a Chef recipe to continue after a reboot (Windows)?

I am trying to use Chef to automate installation/deployment of an older version of a Windows product (Sharepoint 2007, specifically), and I almost have it working, but, at one point during the installation, the installer encounters an "application compatibility" problem and pops up a window that asks whether to continue or not. 我试图使用Chef来自动执行Windows产品旧版本(特别是SharePoint 2007)的安装/部署,并且几乎可以正常工作,但是在安装过程中的某一时刻,安装程序遇到“应用程序兼容性”问题并弹出一个窗口,询问是否继续。 If I click to continue, the installation continues to the end, and it works properly. 如果单击以继续,安装将继续进行到最后,并且可以正常工作。

I found a way to avoid the popup, by adding an "Appcompat" key in the windows registry, but if I use regedit to add the key during the Chef run, I have to get Chef to reboot the machine and then to continue with the rest of the installation afterwards. 通过在Windows注册表中添加“ Appcompat”密钥,我找到了一种避免弹出窗口的方法,但是,如果我在Chef运行期间使用regedit添加密钥,则必须让Chef重新启动计算机,然后继续执行之后进行其余的安装。

I've tried a recipe with something like: 我已经尝试过类似的食谱:

reboot 'Restart Computer' do
  action :nothing
end


powershell_script "install-Sharepoint2007-PREREQUISITES" do
code <<-EOH

regedit /s .\appcompat.reg

EOH

notifies :reboot_now, 'reboot[Restart Computer]', :immediately

end


powershell_script "install-Sharepoint2007" do
code <<-EOH

... the rest of the installation....

EOH

notifies :reboot_now, 'reboot[Restart Computer]', :immediately

end

but the processing basically stops, after the reboot after setting the registry key. 但是在设置注册表项后重新启动后,处理基本上停止了。

So I was wondering: Is there a way to do this with Chef? 所以我想知道:有没有办法和厨师一起做?

Thanks, Jim 谢谢,吉姆

EDIT: 编辑:

I find it hard to use just the comments because of lack of formatting so I'm adding information on what I have tried thus far here. 由于缺乏格式,我发现仅使用注释就很困难,因此我将在此处添加到目前为止我已经尝试过的信息。

Basically, the only way I can get the chef-client to run in a scheduled task so far is to do a "ONCE" scheduled task, setting the time for the task to run (so far, I'm manually setting the time in my schtasks command, just to test). 基本上,到目前为止,我可以让Chef-Client在计划任务中运行的唯一方法是执行“一次”计划任务,设置任务运行的时间(到目前为止,我正在手动设置时间我的schtasks命令,只是为了测试)。

When I do that, and set the "/RU" to SYSTEM, I can see the "chef-client -o" start to run and it actually seems to complete, but I see errors in the Sharepoint installer logs, and in particular, it appears that some of the steps in the psconfig (the Sharepoint command line configuration tool) are failing. 当我这样做时,将“ / RU”设置为SYSTEM时,我可以看到“ chef-client -o”开始运行,并且实际上似乎已经完成,但是在Sharepoint安装程序日志中,尤其是在我看到错误时,看来psconfig(Sharepoint命令行配置工具)中的某些步骤失败了。

I think/guess that the reason for those failures is that the schtasks is running the "chef-client -o" as the wrong Windows user. 我认为/猜测这些失败的原因是schtasks以错误的Windows用户身份运行“ chef-client -o”。

The thing is, if I run the "chef-client -o" on the 2nd part cookbook "manually", ie, if I log into the Windows machine and type: 问题是,如果我“手动”在第二部分食谱上运行“ chef-client -o”,即,如果我登录Windows计算机并键入:

chef-client -o install-SHAREPOINT-PART2 厨师客户端-o install-SHAREPOINT-PART2

Then, Sharepoint gets installed and configured correctly. 然后,Sharepoint被正确安装和配置。

So, the thing I'm stuck on now is when I do that same "chef-client -o" command via schtasks, what should I use as the "/RU" and "/RP" for the schtasks command? 因此,我现在遇到的问题是,当我通过schtasks执行相同的“ chef-client -o”命令时,应该将什么用作schtasks命令的“ / RU”和“ / RP”?

Thanks, Jim 谢谢,吉姆

EDIT 2: Sorry, I forgot to include the schtasks line in the first cookbook/recipe, which sets up the task for the second cookbook/recipe chef run: 编辑2:对不起,我忘了在第一本食谱/食谱中加入schtasks行,该代码为第二本食谱/食谱厨师运行设置了任务:

schtasks /create /tn Task_Name /tr "chef-client -o install-SHAREPOINT2007FULL-PART2" /sc once /RU "SYSTEM" /SD 06/27/2015 /ST 12:30

EDIT 3: The original reason that I was looking into this (having Chef work "through" a reboot) was that as part of installing Sharepoint, I had to set a Windows registry key, and I thought that I had to reboot to make that registry change effective for the rest of the install process. 编辑3:我调查此问题的原始原因(使Chef通过“重新启动”进行工作)是,在安装Sharepoint的过程中,我必须设置一个Windows注册表项,并且我认为必须重新启动才能做到这一点注册表更改对其余安装过程有效。

However, I did some testing yesterday, and it appears that is not the case. 但是,我昨天做了一些测试,看来情况并非如此。 I can make the registry change, then do the rest of the installation, without having to reboot in between. 我可以更改注册表,然后完成其余的安装,而不必在两者之间重新启动。

So, bottom line is that I didn't need to process after the reboot after all. 因此,最重要的是,毕竟重启后我不需要进行处理。

But anyway, hopefully some of the info here may help someone later. 但是无论如何,希望这里的某些信息以后可能会对某人有所帮助。 The main thing I found was was I couldn't get it to work using ONSTART with the /Z /V1... I had to use the ONCE and would have had to have code in my Chef recipe to figure out the date and time to fire the ONCE tasks. 我发现的主要内容是我无法使用带有/ Z / V1的ONSTART来工作...我不得不使用ONCE,并且不得不在我的Chef配方中包含代码来确定日期和时间触发一次ONCE任务。

All in all I would say not as-is. 总而言之,我会说不是原样。

You have to tweak things to work there by doing a two pass run. 您必须通过两遍运行来调整要在此处进行的工作。

Your first pass will add the registry information, plan a chef-run in a few minutes (targetting after the reboot) if chef is not installed as a service, and reboot. 您的第一遍将添加注册表信息,如果未将Chef安装为服务,则在几分钟之内(计划在重新引导之后)计划一次Chef运行,然后重新引导。

The second pass should go over the registry part and do the rest of the installation. 第二遍应该遍历注册表部分并完成其余的安装。

According to your code and assuming Chef is installed as an autostarting service on the node you could add just a guard to your powershell resource like this: 根据您的代码,并假设Chef是作为自动启动服务安装在节点上的,则可以向您的Powershell资源添加一个防护,如下所示:

powershell_script "install-Sharepoint2007-PREREQUISITES" do
  code <<-EOH
    regedit /s .\appcompat.reg
  EOH
  notifies :reboot_now, 'reboot[Restart Computer]', :immediately
  not_if registry_data_exists?(
              KEY_PATH,
              { :name => "NAME", :type => TYPE, :data => VALUE },
              ARCHITECTURE
         )
end

Doc on the guards here and on the registry recipe helpers here 文件上的卫兵在这里 ,并在注册表配方佣工这里

You can have chef run a scheduled task on start up to run chef. 您可以让厨师在启动时运行预定任务以运行厨师。

windows_task 'Chef client' do
  user 'SYSTEM'
  command 'chef-client -L C:\chef\chef-client.log'
  run_level :highest
  frequency :onstart
  frequency_modifier 30
  action :create
end

Then when the node reboots, chef will run again. 然后,当节点重新启动时,chef将再次运行。

Consider the following recipe that joins a windows computer to a domain, reboots, runs chef (as a scheduled task), then deletes the scheduled task. 考虑以下配方,该配方将Windows计算机加入域,重新引导,运行Chef(作为计划任务),然后删除计划任务。

https://github.com/NetDocuments/ad-join-cookbook/blob/master/resources/domain_join.rb https://github.com/NetDocuments/ad-join-cookbook/blob/master/resources/domain_join.rb

Update There is a RFC proposal to change the exit codes of chef to allow for intellegently handling reboots. 更新有一个RFC提案,用于更改Chef的退出代码,以允许智能地处理重启。

CHEF RFC #62 首席RFC#62

I have done it using FLAG file method, example given below. 我已经使用FLAG文件方法完成此操作,下面给出了示例。 Example of domain join- 域加入的示例-

---------------------------Script Start------------------------

    powershell_script 'Domain_Join' do
    guard_interpreter :powershell_script
    code -domainJoin
    $currentTime = Get-Date
    $currentTimeString = $currentTime.ToString()

  $systemDomain = (Get-WmiObject Win32_ComputerSystem).Domain
  If (($systemDomain) -eq 'domainName')
  { 
    Try {
  write-host "$env:computerName is DOMAIN MEMBER"
  Remove-Item C:\\DomainJoinFlag.txt -ErrorAction Stop
  Unregister-ScheduledTask -TaskName "Chef client schedule_DJ" -Confirm:$false
  } # end of Try
          Catch [System.Management.Automation.ItemNotFoundException]
            { write-host "Server is already domain member, Or Exception raised due to either missing FLAG file or Server startup schedule task configuration." 
              eventcreate /t INFORMATION /ID 0909 /L APPLICATION /SO "ChefClient_$env:computerName" /D "Server is already domain member, Or Exception raised due to either missing FLAG file or Server startup schedule task configuration. Refer to the CHEF reciepie for DomainJoin or check Administrative credentials for creting schedule task"}
            }
    else { write-host "$env:computerName is NOT domain member, joining the server to the domain. Server will be rebooting in a while..."
            eventcreate /t INFORMATION /ID 0909 /L APPLICATION /SO "ChefClient_$env:computerName" /D "Joining the server : $env:ComputerName to the domain ININLAB.COM (Server Time): $currentTimeString"
            New-Item C:\\DomainJoinFlag.txt -type file -force
            write-host "$env:computerName DOMAIN JOIN INITIATED for the server"
            $cred = New-Object System.Management.Automation.PsCredential("domain\\domain_user", (ConvertTo-SecureString "Password" -AsPlainText -Force))
            Add-Computer -DomainName "domainName" -Credential $cred -OUPath "OU=HyperV,OU=Infrastructure,OU=Servers,DC=domain,DC=name"
            shutdown -r -t 120
            } #end_of_else
            domainJoin
  notifies :run, 'windows_task[Chef client schedule_DJ]', :immediately
end

windows_task 'Chef client schedule_DJ' do
  user 'SYSTEM'
  command 'chef-client -L C:\chef\chef-client_after_reboot_domainJoin.log'
  run_level :highest
  frequency :onstart
  frequency_modifier 30
  action :create
  only_if { ::File.exist?('C:\\DomainJoinFlag.txt') }
end

---------------------------Script Ends------------------------

Use rakefile to trigger the converge. 使用rakefile触发收敛。 You should also give some sleep time after windows reboot and re-converge again: Here's and example. Windows重新启动并再次重新收敛后,您还应该留出一些睡眠时间:这是示例。

sh 'bundle exec kitchen converge'
      sleep 120
      sh 'bundle exec kitchen verify'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 厨师重新启动资源会导致厨师运行超时,然后Windows服务器才能在更新和恢复配方后启动备份 - Chef reboot resource causes chef run to time out before Windows server is able to start back up after update and resume recipe Windows Update厨师食谱 - Windows Update Chef Recipe 如何使用 Chef Windows 重启资源仅重启一次 - How to use a Chef Windows reboot resource to reboot only once 检查是否需要重新启动并在重新启动后继续执行 Powershell 脚本? - Check if a reboot is needed and continue Powershell script after reboot? 更新/重新启动后Windows Server时间不正确 - Windows Server Time Incorrect After Updates/Reboot Windows 计划任务在重新启动后不起作用 - Windows Scheduled Task not working after a reboot 在 Windows 上重启后 Docker 不会自动启动 - Docker will not start automatically after reboot on Windows Windows 7路径直到重启后才由安装设置 - windows 7 path not set by install until after reboot 通过厨师配方调用,SQLPLUS无法识别Windows 12R2中的Oracle_Home环境变量 - Called through chef recipe, SQLPLUS unable to identify Oracle_Home environment variable in Windows 12R2 当存储库为AWS CodeCommit时,如何从Windows上的Chef配方执行GIT命令? - How to execute GIT commands from Chef recipe on Windows when repository is AWS CodeCommit?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM