Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Chef infra 厨师长-如何重新启动虚拟机并继续执行操作_Chef Infra_Chef Recipe_Chef Solo - Fatal编程技术网

Chef infra 厨师长-如何重新启动虚拟机并继续执行操作

Chef infra 厨师长-如何重新启动虚拟机并继续执行操作,chef-infra,chef-recipe,chef-solo,Chef Infra,Chef Recipe,Chef Solo,在厨师菜谱中,我需要在执行某些操作后重新启动节点, 重启完成后,我需要继续执行其他操作: 配方: -行动1 -行动2 -重新启动 -行动3 -行动4 我检查了社区中现有的一些食谱:reboot handler、chef reboot、chef reboot、chef dominous,但我无法让它们中的任何一个正常工作 厨师有什么方法可以满足我的需要吗? 请提供详细的例子 非常感谢您的帮助。使用来实现一系列状态转换如何?这种方法可以与cookbook结合起来管理实际的重新启动 例子 defaul

在厨师菜谱中,我需要在执行某些操作后重新启动节点, 重启完成后,我需要继续执行其他操作:

配方: -行动1 -行动2 -重新启动 -行动3 -行动4

我检查了社区中现有的一些食谱:reboot handler、chef reboot、chef reboot、chef dominous,但我无法让它们中的任何一个正常工作

厨师有什么方法可以满足我的需要吗? 请提供详细的例子

非常感谢您的帮助。

使用来实现一系列状态转换如何?这种方法可以与cookbook结合起来管理实际的重新启动

例子 default.rb 行动1.rb 行动2.rb
这是我的食谱,你可以试试。
#食谱名称::重新启动测试
#配方::默认值
bash“重启”吗
cwd'/tmp'
代码/etc/rc.d/rc.local
cp/etc/rc.d/rc.local/etc/rc.d/rc.local\U bkp
echo“/bin/chef client”>>/etc/rc.d/rc.local
重新启动
EOH
忽略错误为真
如果do::File.exists不存在('/tmp/reboot.lock')结束
如果'ls-lrth/tmp/reboot.lock'
结束
#这是您需要为配置自动化编码的地方,如execute#资源,但在bash资源“CHEF-CLIENT-#EXIT”之前
执行“touch”do
命令'/bin/touch/tmp/suman.test'
结束
bash“厨师、客户、退出”怎么办

代码我使用标志文件方法完成了它,下面给出了一个示例。 域连接示例-

大宗报价


抱歉没有澄清,这是Linux:Centos 6.5和Redhat 6.x我发现类似的概念是chef restart cookbook提出的,它也有一个很好的方法来重新启动登录shell:但它会抛出许多错误,似乎它已经有一段时间没有更新了,现在与Chef或其他一些库的最新版本不兼容。感谢您的回复。我看到的例子是,重新启动是在厨师运行结束时运行的,但是我需要在重启之后添加另一个动作,我的意思是我需要在执行过程中重新启动,而厨师没有“切断运行”并在重新启动下一个动作之后保持运行。重新启动处理程序的问题是,它会在最后安排重新启动。我发现最相似的概念是chef restart cookbook:但它似乎很旧,不能与较新的chef版本一起使用,而且不支持Centos/Redhat,所以。@user2620348这就是使用标记的目的。“doAction1”标记允许在重新启动前应用功能,“doAction2”标记允许在重新启动后应用功能。“doAction1”标记首先应用在哪里?在您的示例中,我可以看到doAction2的应用位置,但我看不到doAction2的设置位置。@Stefanoricardi您已经指出需要一些东西来触发工作流。提问者没有具体说明标准。设置标记(从而触发某些内容)的最简单方法是使用“刀标记”命令。请解释你的答案。请解释你的答案
#
# Action recipes
#
include_recipe "mycookbook::action1"
include_recipe "mycookbook::action2"

#
# State transitions
#
if tagged?("doAction1")

  untag("doAction1")
  tag("doAction2")

elsif tagged?("doAction2")

  untag("doAction2")

end    
if tagged?("doAction1")

  ..
  ..

end
include_recipe "reboot-handler"

if tagged?("doAction2")

  ..
  ..

  # Trigger reboot at end of chef run
  node.run_state['reboot'] = true
end
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
---------------------------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------------------------