简体   繁体   English

在第二次运行Chef-client时,“ link”上的docker_container的惰性属性未得到解析并传递了不可读的值

[英]In the second run of chef-client, lazy attribute of docker_container on “link” is not getting resolved and passed unreadable value

my first time to ask stuff on stack-overflow, here in china i seldom able to meet any chef developer to talk about my problem so i am posting it here to seek for help. 我第一次问堆栈溢出问题,在中国,我很少能见到任何厨师开发人员谈论我的问题,因此我将其张贴在这里寻求帮助。 This issue has been bothering me for weeks and i am still trying to settle it. 这个问题困扰了我好几个星期,而我仍在努力解决它。

here are my error msg: 这是我的错误信息:

  * directory[/root/tools/projectname/../bootproxy] action create (up to date)

* template[/root/tools/projectname/../bootproxy/oc.proxy.conf] action create (up to date) * directory[/root/tools/projectname/../bootproxy] action create (up to date) * file[/tmp/dockerinfo.txt] action delete - delete file /tmp/dockerinfo.txt * bash[docker ps -a|grep -v CONTAINER|grep -v monitor|awk '{print $1, $NF}'] action run - execute "bash" "/tmp/chef-script20170319-2107-fx41as" * ruby_block[result] action run - execute the ruby block result * docker_container[bootproxy] action redeploy - stopping bootproxy (will kill after 30s) - deleting bootproxy ================================================================================ Error executing action redeploy on resource 'docker_container[bootproxy]' ================================================================================ *模板[/root/tools/projectname/../bootproxy/oc.proxy.conf]操作创建(最新)*目录[/root/tools/projectname/../bootproxy]操作创建(最新) * file [/tmp/dockerinfo.txt]操作删除-删除文件/tmp/dockerinfo.txt * bash [docker ps -a | grep -v CONTAINER | grep -v monitor | awk'{print $ 1,$ NF}']动作运行-执行“ bash”“ / tmp / chef-script20170319-2107-fx41as” * ruby​​_block [结果]动作运行-执行ruby块结果* docker_container [bootproxy]动作重新部署-停止bootproxy(将在30秒后终止)-删除引导代理================================================= =============================对资源'docker_container [bootproxy]'执行动作redeploy时出错======= ================================================== =======================

Docker::Error::ServerError
--------------------------
Could not get container for bootproxy

Cookbook Trace:
---------------
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:319:in `block (3 levels) in <class:DockerContainer>'
/var/chef/cache/cookbooks/docker/libraries/helpers_base.rb:66:in `with_retries'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:250:in `block (2 levels) in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:81:in `converge_if_changed'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:247:in `block in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:169:in `call_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:360:in `block in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:169:in `call_action'
/var/chef/cache/cookbooks/docker/libraries/docker_container.rb:403:in `block in <class:DockerContainer>'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:78:in `run_action'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block (2 levels) in converge'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `each'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block in converge'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:105:in `converge'

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/webserver/recipes/default.rb

218:         docker_container container_name do
219:           repo docker[:image]
220:           tag docker[:tag]
221:           #Add all docker link
222:           # links node.set[:linking]
223:           links lazy{node.run_state[:linking]}
224:           env docker[:env]
225:           command docker[:command]
226:           kill_after 30
227:     #      autoremove true
228:           action :redeploy
229:           port docker[:ports]
230:           volumes node.default["bindvolume"]
231:           cap_add 'SYS_ADMIN'
232:           devices []
233:           privileged true
234:           timeout 30
235:     #      {["/dev/fuse"]}
236:         end
237:       else
238:         docker_container container_name do
239:           repo docker[:image]
240:           tag docker[:tag]
241:           #Add all docker link
242:           links node.run_state[:linking]
243:           env docker[:env]
244:           command docker[:command]
245:           kill_after 30
246:     #      autoremove true
247:           action :redeploy
248:           port docker[:ports]
249:           volumes node.default["bindvolume"]
250:           cap_add 'SYS_ADMIN'
251:           devices []
252:           privileged true
253:           timeout 30
254:     #      {["/dev/fuse"]}
255:         end
256:       end
257: 
258:       if (not (defined?(docker[:exec])).nil?) && (not "#{docker[:exec]}" == "")
259:         execute 'execute command inside docker' do
260:         command "docker exec -i #{container_name} /bin/bash -c \'#{docker[:exec]}\'"
261:         end
262:       end
263: 
264:       etchosts.push("#{container_name}:#{container_name}")
265:     end
266: 
267:     #Add proxy.conf to folder if bootproxy defined
268:     if defined?(node[:externalmode]) && node[:externalmode].eql?("bootproxy")
269:       #Prepare bootproxy directories
270:       directory "#{node[:deploycode][:basedirectory]}../bootproxy" do

Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/webserver/recipes/default.rb:218:in `block in from_file'

docker_container("bootproxy") do
  action [:redeploy]
  retries 0
  retry_delay 2
  default_guard_interpreter :default
  declared_type :docker_container
  cookbook_name "webserver"
  recipe_name "default"
  kill_after 30
  repo "daocloud.io/library/nginx"
  tag "stable-alpine"
  exposed_ports {"80/tcp"=>{}, "5000/tcp"=>{}}
  port_bindings {"80/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"80"}], "5000/tcp"=>[{"HostIp"=>"0.0.0.0", "HostPort"=>"5000"}]}
  port ["80:80", "5000:5000"]
  volumes_binds ["/root/tools/projectname/../bootproxy:/etc/nginx/conf.d/"]
  links #<ChefCompat::CopiedFromChef::Chef::DelayedEvaluator:0x000000055c4a90@/var/chef/cache/cookbooks/webserver/recipes/default.rb:223>
  cap_add ["SYS_ADMIN"]
  privileged true
  timeout 30
  connection #<Docker::Connection:0x00000008301238 @url="unix:///", @options={:socket=>"/var/run/docker.sock", :read_timeout=>60}>
  network_mode "bridge"
  detach true
  signal "SIGTERM"
end

Running handlers: [2017-03-19T21:20:15+08:00] ERROR: Running exception handlers Running handlers complete [2017-03-19T21:20:15+08:00] ERROR: Exception handlers complete Chef Client failed. 正在运行的处理程序:[2017-03-19T21:20:15 + 08:00]错误:正在运行的异常处理程序正在运行的处理程序完成[2017-03-19T21:20:15 + 08:00]错误:异常处理程序完成Chef Client失败。 20 resources updated in 34 seconds [2017-03-19T21:20:15+08:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out [2017-03-19T21:20:15+08:00] ERROR: docker_container[bootproxy] (webserver::default line 218) had an error: Docker::Error::ServerError: Could not get container for bootproxy 34秒内更新了20个资源[2017-03-19T21:20:15 + 08:00]致命:Stacktrace转储至/var/chef/cache/chef-stacktrace.out [2017-03-19T21:20:15 + 08 :00]错误:docker_container [bootproxy](webserver ::默认行218)发生错误:Docker :: Error :: ServerError:无法获取bootproxy的容器

[2017-03-19T21:20:15+08:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) [2017-03-19T21:20:15 + 08:00]致命:Chef :: Exceptions :: ChildConvergeError:Chef运行进程未成功退出(退出代码1)

and here are my codes: 这是我的代码:

  node.run_state[:linking] = []
  #Special handling if bootproxy,  get all local running docker id and name and link into bootproxy
  if localfolder.eql?("bootproxy")
    container_name = localfolder
    node.set[:dockerinfo] = []
    results = "/tmp/dockerinfo.txt"
    file results do
      action :delete
    end

    cmd = "docker ps -a|grep -v CONTAINER|grep -v monitor|awk \'{print $1, $NF}\'"
    bash cmd do
      code <<-EOH
      #{cmd} > #{results}
      EOH
    end

    ruby_block "result" do
      only_if { "cat #{results}| wc -l;while [ $? -ne 0 ]; do cat #{results}| wc -l;done" }
      # only_if { ::File.exists?(results) }
      block do
        f = File.open(results)
        dockerinfo = Hash.new
        f.each do |line|
          dockerinfo[line.chomp.split(' ')[0]] = line.chomp.split(' ')[1]
        end
        f.close
        node.set[:dockerinfo] = dockerinfo
        node.run_state[:linking] = dockerinfo
        node.run_state[:linking] = []
        node.set[:dockerinfo].each do |hash, dockername|
          node.run_state[:linking].push("#{dockername}:#{dockername}")
        end
      end
    end
  else
    node.run_state[:linking] = etchosts
  end

  if node.default["bindvolume"].eql?([":"])
    node.default["bindvolume"] = nil
  end
  if localfolder.eql?("bootproxy")
    # Using lazy evaluation if bootproxy
    docker_container container_name do
      repo docker[:image]
      tag docker[:tag]
      #Add all docker link
      # links node.set[:linking]
      links lazy{node.run_state[:linking]}
      env docker[:env]
      command docker[:command]
      kill_after 30
#      autoremove true
      action :redeploy
      port docker[:ports]
      volumes node.default["bindvolume"]
      cap_add 'SYS_ADMIN'
      devices []
      privileged true
      timeout 30
#      {["/dev/fuse"]}
    end
  else
    docker_container container_name do
      repo docker[:image]
      tag docker[:tag]
      #Add all docker link
      links node.run_state[:linking]
      env docker[:env]
      command docker[:command]
      kill_after 30
#      autoremove true
      action :redeploy
      port docker[:ports]
      volumes node.default["bindvolume"]
      cap_add 'SYS_ADMIN'
      devices []
      privileged true
      timeout 30
#      {["/dev/fuse"]}
    end
  end

What i am trying to do here, is to run a set of docker by chef docker cookbook version 2.14.3, with names looping into "localfolder", and when localfolder = "bootproxy", execute bash command to check what dockers are currently running and link them by a nginx docker named as "bootproxy". 我要在这里执行的操作是通过厨师docker cookbook 2.14.3版运行一组docker,名称循环到“ localfolder”,并且当localfolder =“ bootproxy”时,执行bash命令以检查当前正在运行的docker并通过名为“ bootproxy”的nginx泊坞窗链接它们。

My issue here is, whenever i cleared all my cache or after i have re-uploaded all my cookbook "webserver", chef-client runs fine without error. 我的问题是,每当我清除所有缓存或重新上传所有食谱“ webserver”后,chef-client都可以正常运行而没有错误。 But when i rerun the chef-client, i got 但是当我重新运行厨师客户时,我得到了

Docker::Error::ServerError
--------------------------
Could not get container for bootproxy

due to the value of "links" in "docker_container" resources became "#" instead of an array that included the current running docker names like [ "container1:container1", "container2:container2", "container3:container3"]. 由于“ docker_container”中“ links”的值,资源变为“#”,而不是包含当前正在运行的docker名称(例如[“ container1:container1”,“ container2:container2”,“ container3:container3”)的数组。 So i suspect that the ruby_block that trying to get value from the host is being cached and not running after the first successive execution. 因此,我怀疑尝试从主机获取值的ruby_block正在缓存,并且在第一次连续执行后未运行。 My removal of cache (rm -rf /var/chef/cache) proved it but i cannot define removal of cache inside cookbook(not a neat way to work it out too). 我删除了缓存(rm -rf / var / chef / cache)证明了这一点,但我无法在Cookbook中定义删除缓存(这也不是一种有效的解决方法)。 I need to make the chef-client able to rerun as i am using it to deploy my set of codes in the whole envionment. 我需要使厨师客户端能够重新运行,因为我正在使用它在整个环境中部署我的代码集。 Please give me any advise for this. 请给我任何建议。

Thanks! 谢谢!

I think you missed fixing the second resource, it isn't using the lazy{} helper. 我认为您错过了修复第二个资源的机会,它没有使用lazy{}帮助程序。

Overall this code is kind of a mess so it's really hard to tell what it is doing in the first place. 总体而言,此代码有些混乱,因此一开始就很难分辨它在做什么。 I recommend writing a lot of tests and maybe more comments. 我建议编写大量测试,也许还要发表更多评论。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM