Skip to content

Commit 1bf015a

Browse files
committed
Merge pull request #155 from hirocaster/watch-services
Add LWRP services watch
2 parents 52fc5aa + f9a179b commit 1bf015a

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ the `consul::ui` recipe in your node's `run_list`.
413413
handler "chef-client"
414414
end
415415

416+
##### Adding services watch
417+
consul_services_watch_def 'services-name' do
418+
handler "chef-client"
419+
end
420+
416421
##### Adding service watch
417422
consul_service_watch_def 'service-name' do
418423
passingonly true

providers/services_watch_def.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use_inline_resources
2+
3+
action :create do
4+
file new_resource.path do
5+
user node['consul']['service_user']
6+
group node['consul']['service_group']
7+
mode 0600
8+
content new_resource.to_json
9+
10+
action :create
11+
end
12+
end
13+
14+
action :delete do
15+
file new_resource.path do
16+
action :delete
17+
end
18+
end

resources/services_watch_def.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'json'
2+
3+
actions :create, :delete
4+
default_action :create
5+
6+
attribute :name, name_attribute: true, required: true, kind_of: String
7+
attribute :handler, required: true, kind_of: String
8+
9+
def path
10+
::File.join(node['consul']['config_dir'], "watch-services.json")
11+
end
12+
13+
def to_json
14+
JSON.pretty_generate(to_hash)
15+
end
16+
17+
def to_hash
18+
hash = {
19+
watches:[
20+
{
21+
type: 'services',
22+
handler: handler
23+
}
24+
]
25+
}
26+
hash
27+
end

0 commit comments

Comments
 (0)