Skip to content

Commit

Permalink
Merge 7f44766 into 60e3072
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinheavyside committed Mar 12, 2015
2 parents 60e3072 + 7f44766 commit a6a0d68
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
14 changes: 12 additions & 2 deletions README.md
Expand Up @@ -419,9 +419,9 @@ the `consul::ui` recipe in your node's `run_list`.
notifies :reload, 'service[consul]'
end

##### Adding service with check
##### Adding services with checks

consul_service_def 'voice1' do
consul_service_def "voice1' do
port 5060
tags ['_sip._udp']
check(
Expand All @@ -431,6 +431,16 @@ the `consul::ui` recipe in your node's `run_list`.
notifies :reload, 'service[consul]'
end

consul_service_def 'server1' do
port 80
tags ['http']
check(
interval: '10s',
http: 'http://localhost:80'
)
notifies :reload, 'service[consul]'
end

##### Removing service

consul_service_def 'voice1' do
Expand Down
2 changes: 2 additions & 0 deletions resources/check_def.rb
Expand Up @@ -23,6 +23,7 @@
attribute :name, name_attribute: true, required: true, kind_of: String
attribute :id, kind_of: String
attribute :script, kind_of: String
attribute :http, kind_of: String
attribute :ttl, kind_of: String
attribute :interval, kind_of: String
attribute :notes, kind_of: String
Expand All @@ -48,6 +49,7 @@ def to_hash
hash[:check][:id] = id unless id.nil?
hash[:check][:script] = script unless script.nil?
hash[:check][:ttl] = ttl unless ttl.nil?
hash[:check][:http] = http unless http.nil?
hash[:check][:interval] = interval unless interval.nil?
hash[:check][:notes] = notes unless notes.nil?
hash
Expand Down
8 changes: 6 additions & 2 deletions resources/service_def.rb
Expand Up @@ -25,7 +25,7 @@
attribute :port, kind_of: Integer
attribute :tags, kind_of: Array, default: nil
attribute :check, kind_of: Hash, default: nil, callbacks: {
'Checks must be a hash containing either a `:ttl` key/value or a `:script` and `:interval` key/value' => ->(check) do
'Checks must be a hash containing either a `:ttl` key/value or a `:script/:http` and `:interval` key/value' => ->(check) do
Chef::Resource::ConsulServiceDef.validate_check(check)
end
}
Expand All @@ -35,14 +35,18 @@ def self.validate_check(check)
return false
end

if check.key?(:ttl) && (!check.key?(:interval) && !check.key?(:script))
if check.key?(:ttl) && ( [:interval, :script, :http].none?{|key| check.key?(key)} )
return true
end

if check.key?(:interval) && check.key?(:script)
return true
end

if check.key?(:interval) && check.key?(:http)
return true
end

false
end

Expand Down
Expand Up @@ -4,5 +4,6 @@
script "curl http://localhost:8888/health"
interval "10s"
ttl "50s"
http "http://localhost:8888/health"
notes "Blahblah"
end
9 changes: 7 additions & 2 deletions spec/unit/resources/check_def_spec.rb
Expand Up @@ -13,8 +13,13 @@
end

it "register the check" do
['"name": "dummy name"', '"id": "uniqueid"', '"script": "curl http://localhost:8888/health"',
'"interval": "10s"', '"ttl": "50s"', '"notes": "Blahblah"'].each do |content|
['"name": "dummy name"',
'"id": "uniqueid"',
'"script": "curl http://localhost:8888/health"',
'"http": "http://localhost:8888/health"',
'"interval": "10s"',
'"ttl": "50s"',
'"notes": "Blahblah"'].each do |content|
expect(chef_run).to render_file(check_def_path)
.with_content(content)
end
Expand Down

0 comments on commit a6a0d68

Please sign in to comment.