Created
August 11, 2011 12:21
-
-
Save octplane/1139515 to your computer and use it in GitHub Desktop.
Last Recipe that populates the registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| order = node.recipes | |
| if order[-1] != "lastrecipe" | |
| Chef::Log.error("Last Recipe should be the last recipe to run") | |
| raise "Please refactor my runlist" | |
| end | |
| # This recipe is tightly integrated with monitored in fotonauts and recipe | |
| # firstrecipe | |
| ruby_block "Save Monitored cache" do | |
| block do | |
| neu = node[:monitored][:next] | |
| # Move current monitor to next value | |
| # Remove old from registry | |
| node[:monitored] = { | |
| :current => node[:monitored][:content][neu].to_hash | |
| } | |
| CACHE_FNAME = '/var/spool/check_monitored.yml' | |
| @services = {} | |
| @loaded = false | |
| File.unlink(CACHE_FNAME) if File.exists?(CACHE_FNAME) | |
| monitored_nodes = search(:node, "monitored:[* TO *]") | |
| monitored_nodes.each do |n| | |
| hostname = n[:hostname] | |
| root = n[:monitored][:current] || {} | |
| root.each do |name, description| | |
| description = description.to_hash | |
| description['depends'] = (description['depends'] || []).map {|d| | |
| if d.index('@') == nil | |
| d + '@' + hostname | |
| else | |
| d | |
| end | |
| } | |
| @services[name + '@' + hostname] = description | |
| end | |
| end | |
| File.open(CACHE_FNAME, "w") do |f| | |
| f.puts @services.to_yaml | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment