Skip to content

Commit

Permalink
Merge pull request #155 from hirocaster/watch-services
Browse files Browse the repository at this point in the history
Add LWRP services watch
  • Loading branch information
johnbellone committed Jun 4, 2015
2 parents 52fc5aa + f9a179b commit 1bf015a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -413,6 +413,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
@@ -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
@@ -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 1bf015a

Please sign in to comment.