Skip to content

Commit

Permalink
Update the consul_client HWRP.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbellone committed Feb 9, 2015
1 parent f2a0072 commit 2ad8e63
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 51 deletions.
29 changes: 0 additions & 29 deletions libraries/provider_consul_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,8 @@ def whyrun_supported?
end

action :create do
user node['consul']['user'] do
system true
comment 'consul service user'
home '/dev/null'
shell '/bin/false'
not_if { username == 'root' }
end

group node['consul']['group'] do
system true
append true
members node['consul']['user']
not_if { group_name == 'root' }
end

directory node['consul']['data_dir'] do
user node['consul']['user']
group node['consul']['group']
mode 0755
end

directory node['consul']['config_dir'] do
user node['consul']['user']
group node['consul']['group']
mode 0755
end
end

action :delete do
directory node['consul']['data_dir'] do
action :delete
end
end
end
22 changes: 11 additions & 11 deletions libraries/provider_consul_client_binary.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
class Chef::Provider::ConsulClientBinary < Chef::Provider::ConsulClient
action :create do
super
include_recipe 'libarchive::default'

archive = remote_file Chef::Consul.cached_archive(node) do
source Chef::Consul.remote_url(node)
checksum Chef::Consul.remote_checksum(node)
archive = remote_file "#{Chef::Config[:file_cache_path]}/consul-#{new_resource.version}.zip" do
source new_resource.url
checksum new_resource.checksum
end

libarchive_file 'consul.zip' do
libarchive_file ::File.basename(archive.path) do
path archive.path
extract_to Chef::Consul.install_path(node)
extract_to new_resource.path
extract_options :no_overwrite

action :extract
end

directory File.basename(Chef::Consul.active_binary(node)) do
directory ::Dir.dirname(new_resource.filename) do
recursive true
action :create
owner 'root'
group 'root'
mode '00755'
end

link Chef::Consul.active_binary(node) do
to Chef::Consul.latest_binary(node)
link ::File.join(new_resource.path, 'consul') do
to new_resource.filename
end
end
end
22 changes: 11 additions & 11 deletions libraries/provider_consul_client_source.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
class Chef::Provider::ConsulServiceSource < Chef::Provider::ConsulService
action :create do
super
include_recipe 'golang::default'

directory File.join(node['go']['gopath'], 'src/github.com/hashicorp') do
directory new_resource.path do
recursive true
owner 'root'
group 'root'
mode '00755'
recursive true
action :create
end

git File.join(node['go']['gopath'], '/src/github.com/hashicorp/consul') do
repository 'https://github.com/hashicorp/consul.git'
reference node['consul']['source_revision']
git new_resource.path do
repository new_resource.url
reference new_resource.version
action :checkout
end

golang_package 'github.com/hashicorp/consul' do
action :install
end

directory File.basename(Chef::Consul.active_binary(node)) do
directory ::Dir.dirname(new_resource.filename) do
recursive true
action :create
owner 'root'
group 'root'
mode '00755'
end

link Chef::Consul.active_binary(node) do
to Chef::Consul.source_binary(node)
link ::File.join(new_resource.path, 'consul') do
to new_resource.filename
end
end
end
7 changes: 7 additions & 0 deletions libraries/resource_consul_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ class Chef::Resource::ConsulClient < Chef::Resource::LWRPBase
self.resource_name = :consul_client
actions :create, :delete
default_action :create

attribute :path, kind_of: String, name_attribute: true, required: true
attribute :user, kind_of: String, required: true
attribute :group, kind_of: String, required: true
attribute :url, kind_of: String, required: true, default: nil
attribute :version, kind_of: String, required: true, default: nil
attribute :checksum, kind_of: String, default: nil
end

0 comments on commit 2ad8e63

Please sign in to comment.