Skip to content

Commit

Permalink
Merge 31ed5ac into 57b4105
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbellone committed Feb 10, 2015
2 parents 57b4105 + 31ed5ac commit 7dcf0a9
Show file tree
Hide file tree
Showing 18 changed files with 387 additions and 362 deletions.
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright 2014 John Bellone <jbellone@bloomberg.net>
Copyright 2014 Bloomberg Finance L.P.
Copyright 2014, 2015 John Bellone <jbellone@bloomberg.net>
Copyright 2014, 2015 Bloomberg Finance L.P.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -11,4 +11,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
20 changes: 20 additions & 0 deletions libraries/provider_consul_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Provider::ConsulClient < Chef::Provider::LWRPBase
use_inline_resources if defined?(use_inline_resources)

def whyrun_supported?
true
end

action :create do
end

action :delete do
end
end
35 changes: 35 additions & 0 deletions libraries/provider_consul_client_binary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Provider::ConsulClientBinary < Chef::Provider::ConsulClient
action :create do
include_recipe 'libarchive::default'

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 ::File.basename(archive.path) do
path archive.path
extract_to new_resource.path
extract_options :no_overwrite
action :extract
end

directory ::Dir.dirname(new_resource.filename) do
recursive true
owner 'root'
group 'root'
mode '00755'
end

link ::File.join(new_resource.path, 'consul') do
to new_resource.filename
end
end
end
40 changes: 40 additions & 0 deletions libraries/provider_consul_client_source.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Provider::ConsulServiceSource < Chef::Provider::ConsulService
action :create do
include_recipe 'golang::default'

directory new_resource.path do
recursive true
owner 'root'
group 'root'
mode '00755'
end

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 ::Dir.dirname(new_resource.filename) do
recursive true
owner 'root'
group 'root'
mode '00755'
end

link ::File.join(new_resource.path, 'consul') do
to new_resource.filename
end
end
end
41 changes: 41 additions & 0 deletions libraries/provider_consul_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Provider::ConsulConfig < Chef::Provider::LWRPBase
use_inline_resources if defined?(use_inline_resources)

def whyrun_supported?
true
end

action :create do
directory new_resource.path do
owner new_resource.run_user
group new_resource.run_group
mode '0644'
end

# TODO: (jbellone) Figure out a better way to generate this set of
# options. Right now this is a bit messy. Especially if options
# are added after the fact.
invalid_options = [:path, :run_user, :run_group]
configuration = new_resource.to_hash.reject { |k, v| invalid_options.include?(k) }
file new_resource.filename do
user new_resource.run_user
group new_resource.run_group
content JSON.pretty_generate(configuration, quirks_mode: true)
mode '0600'
action :create
end
end

action :delete do
file new_resource.filename do
action :delete
end
end
end
20 changes: 20 additions & 0 deletions libraries/provider_consul_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Provider::ConsulService < Chef::Provider::LWRPBase
use_inline_resources if defined?(use_inline_resources)

def whyrun_supported?
true
end

action :create do
end

action :delete do
end
end
37 changes: 37 additions & 0 deletions libraries/provider_consul_service_runit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Provider::ConsulServiceSystemd < Chef::Provider::ConsulService
action :start do
runit_service 'consul' do
supports status: true, restart: true, reload: true
action :start
end
end

action :stop do
runit_service 'consul' do
supports status: true, restart: true, reload: true
action :stop
end
end

action :restart do
runit_service 'consul' do
supports status: true, restart: true, reload: true
action :restart
end
end

action :reload do
runit_service 'consul' do
supports status: true, restart: true, reload: true
action :reload
reload_command %Q(#{node['runit']['sv_bin']} hup #{service_name})
end
end
end
40 changes: 40 additions & 0 deletions libraries/provider_consul_service_systemd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Provider::ConsulServiceSystemd < Chef::Provider::ConsulService
action :start do
service 'consul' do
supports status: true, restart: true, reload: true
provider Chef::Provider::Service::Init::Systemd
action [:start, :enable]
end
end

action :stop do
service 'consul' do
supports status: true, restart: true, reload: true
provider Chef::Provider::Service::Init::Systemd
action :stop
end
end

action :restart do
service 'consul' do
supports status: true, restart: true, reload: true
provider Chef::Provider::Service::Init::Systemd
action :restart
end
end

action :reload do
service 'consul' do
supports status: true, restart: true, reload: true
provider Chef::Provider::Service::Init::Systemd
action :reload
end
end
end
10 changes: 10 additions & 0 deletions libraries/provider_consul_service_sysvinit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Provider::ConsulServiceSysvinit < Chef::Provider::ConsulService

end
9 changes: 9 additions & 0 deletions libraries/provider_consul_service_upstart.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Provider::ConsulServiceUpstart < Chef::Provider::ConsulService
end
19 changes: 19 additions & 0 deletions libraries/resource_consul_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

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 :run_user, kind_of: String, required: true
attribute :run_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
62 changes: 62 additions & 0 deletions libraries/resource_consul_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Resource::ConsulConfig < Chef::Resource::LWRPBase
self.resource_name = :consul_config
actions :create, :delete
default_action :create

attribute :path, kind_of: String, required: true, name_attribute: true
attribute :run_user, kind_of: String, required: true
attribute :run_group, kind_of: String, required: true

# @see: http://www.consul.io/docs/agent/options.html
attribute :acl_datacenter, kind_of: String, default: nil
attribute :acl_default_policy, kind_of: String, default: nil
attribute :acl_down_policy, kind_of: String, default: nil
attribute :acl_master_token, kind_of: String, default: nil
attribute :acl_token, kind_of: String, default: nil
attribute :acl_ttl, kind_of: String, default: nil
attribute :addresses, kind_of: Hash, default: nil
attribute :advertise_addr, kind_of: String, default: nil
attribute :bind_addr, kind_of: String, default: nil
attribute :bootstrap, kind_of: [TrueClass, FalseClass], default: false
attribute :bootstrap_expect, kind_of: Number, default: 3
attribute :ca_file, kind_of: String, default: nil
attribute :cert_file, kind_of: String, default: nil
attribute :check_update_interval, kind_of: String, default: nil
attribute :client_addr, kind_of: String, default: nil
attribute :data_dir, kind_of: String, default: nil
attribute :datacenter, kind_of: String, default: nil
attribute :disable_anonymous_signature, kind_of: [TrueClass, FalseClass], default: false
attribute :disable_remote_exec, kind_of: [TrueClass, FalseClass], default: false
attribute :disable_update_check, kind_of: [TrueClass, FalseClass], default: false
attribute :dns_config, kind_of: Hash, default: nil
attribute :domain, kind_of: String, default: nil
attribute :enable_debug, kind_of: [TrueClass, FalseClass], default: false
attribute :enable_syslog, kind_of: [TrueClass, FalseClass], default: false
attribute :encrypt, kind_of: String, default: nil
attribute :key_file, kind_of: String, default: nil
attribute :leave_on_terminate, kind_of: [TrueClass, FalseClass], default: false
attribute :log_level, kind_of: String, default: 'INFO'
attribute :node_name, kind_of: String, default: nil
attribute :ports, kind_of: Hash, default: nil
attribute :protocol, kind_of: String, default: nil
attribute :recursor, kind_of: String, default: nil
attribute :retry_interval, kind_of: Number, default: nil
attribute :server, kind_of: [TrueClass, FalseClass], default: true
attribute :server_name, kind_of: String, default: nil
attribute :skip_leave_on_interrupt, kind_of: [TrueClass, FalseClass], default: false
attribute :start_join, kind_of: Array, default: []
attribute :statsd_addr, kind_of: String, default: nil
attribute :statsite_addr, kind_of: String, default: nil
attribute :syslog_facility, kind_of: String, default: nil
attribute :ui_dir, kind_of: String, default: nil
attribute :verify_incoming, kind_of: [TrueClass, FalseClass], default: false
attribute :verify_outgoing, kind_of: [TrueClass, FalseClass], default: false
attribute :watches, kind_of: Hash, default: nil
end
14 changes: 14 additions & 0 deletions libraries/resource_consul_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Cookbook Name:: consul
# License:: Apache 2.0
#
# Copyright 2014, 2015 Bloomberg Finance L.P.
#

class Chef::Resource::ConsulService < Chef::Resource::LWRPBase
self.resource_name = :consul_service
actions :start, :stop, :restart, :enable, :disable, :reload
default_action :start

attribute :service_name, type: String, name_attribute: true, required: true
end
Loading

0 comments on commit 7dcf0a9

Please sign in to comment.