Skip to content

Commit

Permalink
Add LWRP services watch
Browse files Browse the repository at this point in the history
  • Loading branch information
hirocaster committed May 15, 2015
1 parent 76f7831 commit f9a179b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ the `consul::ui` recipe in your node's `run_list`.
handler "chef-client"
end

##### Adding services watch
consul_services_watch_def 'services-name' do
handler "chef-client"
end

##### Adding service watch
consul_service_watch_def 'service-name' do
passingonly true
Expand Down
18 changes: 18 additions & 0 deletions providers/services_watch_def.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use_inline_resources

action :create do
file new_resource.path do
user node['consul']['service_user']
group node['consul']['service_group']
mode 0600
content new_resource.to_json

action :create
end
end

action :delete do
file new_resource.path do
action :delete
end
end
27 changes: 27 additions & 0 deletions resources/services_watch_def.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'json'

actions :create, :delete
default_action :create

attribute :name, name_attribute: true, required: true, kind_of: String
attribute :handler, required: true, kind_of: String

def path
::File.join(node['consul']['config_dir'], "watch-services.json")
end

def to_json
JSON.pretty_generate(to_hash)
end

def to_hash
hash = {
watches:[
{
type: 'services',
handler: handler
}
]
}
hash
end

0 comments on commit f9a179b

Please sign in to comment.