flock_of_chefs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +0 -0
- data/README.md +0 -0
- data/flock_of_chefs.gemspec +18 -0
- data/lib/flock_of_chefs.rb +2 -0
- data/lib/flock_of_chefs/flocked_api.rb +13 -0
- data/lib/flock_of_chefs/flocked_chef.rb +93 -0
- data/lib/flock_of_chefs/flocked_report.rb +52 -0
- data/lib/flock_of_chefs/loader.rb +8 -0
- data/lib/flock_of_chefs/version.rb +5 -0
- metadata +78 -0
data/CHANGELOG.md
ADDED
File without changes
|
data/README.md
ADDED
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
|
2
|
+
require 'flock_of_chefs/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'flock_of_chefs'
|
6
|
+
s.version = FlockOfChefs::VERSION.version
|
7
|
+
s.summary = 'Flock of chefs'
|
8
|
+
s.author = 'Chris Roberts'
|
9
|
+
s.email = 'chrisroberts.code@gmail.com'
|
10
|
+
s.homepage = 'http://github.com/chrisroberts/flock_of_chefs'
|
11
|
+
s.description = 'Chefs flocking about'
|
12
|
+
s.require_path = 'lib'
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.extra_rdoc_files = ['README.md']
|
15
|
+
s.files = Dir['**/*']
|
16
|
+
s.add_dependency 'chef'
|
17
|
+
s.add_dependency 'dcell', '~> 0.10.0'
|
18
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'thread'
|
2
|
+
# This is for hacking up chef internals
|
3
|
+
# NOTE: Currently this is only mucking around with
|
4
|
+
# Chef::Application::Client. Hopefully CHEF-3478
|
5
|
+
# will get merged and make it much easier to add
|
6
|
+
# the custom functionality we want
|
7
|
+
module FlockOfChefs
|
8
|
+
module FlockedChef
|
9
|
+
def mutex
|
10
|
+
unless(@mutex)
|
11
|
+
@mutex = Mutex.new
|
12
|
+
end
|
13
|
+
@mutex
|
14
|
+
end
|
15
|
+
def run_chef_client
|
16
|
+
puts '*' * 400
|
17
|
+
mutex.synchronize do
|
18
|
+
@chef_client = Chef::Client.new(
|
19
|
+
@chef_client_json,
|
20
|
+
:override_runlist => config[:override_runlist]
|
21
|
+
)
|
22
|
+
@chef_client_json = nil
|
23
|
+
@chef_client.run
|
24
|
+
@chef_client = nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_application
|
29
|
+
unless Chef::Platform.windows?
|
30
|
+
SELF_PIPE.replace IO.pipe
|
31
|
+
|
32
|
+
trap("USR1") do
|
33
|
+
Chef::Log.info("SIGUSR1 received, waking up")
|
34
|
+
SELF_PIPE[1].putc('.') # wakeup master process from select
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if Chef::Config[:version]
|
39
|
+
puts "Chef version: #{::Chef::VERSION}"
|
40
|
+
end
|
41
|
+
|
42
|
+
if Chef::Config[:daemonize]
|
43
|
+
Chef::Daemon.daemonize("chef-client")
|
44
|
+
end
|
45
|
+
|
46
|
+
loop do
|
47
|
+
begin
|
48
|
+
if Chef::Config[:splay]
|
49
|
+
splay = rand Chef::Config[:splay]
|
50
|
+
Chef::Log.debug("Splay sleep #{splay} seconds")
|
51
|
+
sleep splay
|
52
|
+
end
|
53
|
+
run_chef_client
|
54
|
+
if Chef::Config[:interval]
|
55
|
+
Chef::Log.debug("Sleeping for #{Chef::Config[:interval]} seconds")
|
56
|
+
unless SELF_PIPE.empty?
|
57
|
+
client_sleep Chef::Config[:interval]
|
58
|
+
else
|
59
|
+
# Windows
|
60
|
+
sleep Chef::Config[:interval]
|
61
|
+
end
|
62
|
+
else
|
63
|
+
Chef::Application.exit! "Exiting", 0
|
64
|
+
end
|
65
|
+
rescue Chef::Application::Wakeup => e
|
66
|
+
Chef::Log.debug("Received Wakeup signal. Starting run.")
|
67
|
+
next
|
68
|
+
rescue SystemExit => e
|
69
|
+
raise
|
70
|
+
rescue Exception => e
|
71
|
+
if Chef::Config[:interval]
|
72
|
+
Chef::Log.error("#{e.class}: #{e}")
|
73
|
+
Chef::Application.debug_stacktrace(e)
|
74
|
+
Chef::Log.error("Sleeping for #{Chef::Config[:interval]} seconds before trying again")
|
75
|
+
unless SELF_PIPE.empty?
|
76
|
+
client_sleep Chef::Config[:interval]
|
77
|
+
else
|
78
|
+
# Windows
|
79
|
+
sleep Chef::Config[:interval]
|
80
|
+
end
|
81
|
+
retry
|
82
|
+
else
|
83
|
+
Chef::Application.debug_stacktrace(e)
|
84
|
+
Chef::Application.fatal!("#{e.class}: #{e.message}", 1)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
puts '***** HOOKING IN BITS'
|
93
|
+
Chef::Application::Client.send(:include, FlockOfChefs::FlockedChef)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'chef/handler'
|
2
|
+
|
3
|
+
module FlockOfChefs
|
4
|
+
class FlockedReport < Chef::Handler
|
5
|
+
def report
|
6
|
+
if(DCell.me.nil?)
|
7
|
+
setup_dcell!
|
8
|
+
end
|
9
|
+
dnode = DCell.me
|
10
|
+
if(dnode)
|
11
|
+
dnode[:flock_api].node = node.to_hash
|
12
|
+
Chef::Log.info 'Node information successfully stored in flock'
|
13
|
+
else
|
14
|
+
Chef::Log.warn 'Failed to store node information in flock!'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup_dcell!
|
19
|
+
raise 'Flock of chefs cookbook not in use!' unless node[:flock_of_chefs]
|
20
|
+
if(node.recipes.include?('flock_of_chefs::keeper'))
|
21
|
+
# NOTE: just gossip for now, zookeeper later
|
22
|
+
start_args = {
|
23
|
+
:node => node.name,
|
24
|
+
:addr => "tcp://#{node[:ipaddress]}:#{node[:flock_of_chefs][:port]}"
|
25
|
+
}
|
26
|
+
case node[:flock_of_chefs][:registry][:type].to_s
|
27
|
+
when 'zk'
|
28
|
+
require 'dcell/registries/zk'
|
29
|
+
start_args.merge(
|
30
|
+
:registry => {
|
31
|
+
:adapter => 'zk',
|
32
|
+
:host => '127.0.0.1', # allow non-local?
|
33
|
+
:port => 2181
|
34
|
+
}
|
35
|
+
)
|
36
|
+
end
|
37
|
+
DCell.start(start_args)
|
38
|
+
else
|
39
|
+
keeper_node = Chef::Search::Query.new.search(:node, 'recipes:flock_of_chefs\:\:keeper').first.first
|
40
|
+
raise 'Failed to find flock keeper!' unless keeper_node
|
41
|
+
DCell.start(
|
42
|
+
:node => node.name,
|
43
|
+
:addr => "tcp://#{node[:ipaddress]}:#{node[:flock_of_chefs][:port]}",
|
44
|
+
:directory => {
|
45
|
+
:id => keeper_node.name,
|
46
|
+
:address => "tcp://#{keeper_node[:ipaddress]}:#{keeper_node[:flock_of_chefs][:port]}"
|
47
|
+
}
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flock_of_chefs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Roberts
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: &8367760 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *8367760
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: dcell
|
27
|
+
requirement: &8366980 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.10.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *8366980
|
36
|
+
description: Chefs flocking about
|
37
|
+
email: chrisroberts.code@gmail.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files:
|
41
|
+
- README.md
|
42
|
+
files:
|
43
|
+
- CHANGELOG.md
|
44
|
+
- README.md
|
45
|
+
- flock_of_chefs.gemspec
|
46
|
+
- lib/flock_of_chefs.rb
|
47
|
+
- lib/flock_of_chefs/loader.rb
|
48
|
+
- lib/flock_of_chefs/flocked_report.rb
|
49
|
+
- lib/flock_of_chefs/flocked_chef.rb
|
50
|
+
- lib/flock_of_chefs/version.rb
|
51
|
+
- lib/flock_of_chefs/flocked_api.rb
|
52
|
+
- flock_of_chefs-0.0.1.gem
|
53
|
+
homepage: http://github.com/chrisroberts/flock_of_chefs
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.17
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Flock of chefs
|
77
|
+
test_files: []
|
78
|
+
has_rdoc: true
|