Skip to content

Commit

Permalink
Merge pull request #68 from wilreichert/config_dir
Browse files Browse the repository at this point in the history
set correct etc config directory for default consul behavior
  • Loading branch information
johnbellone committed Oct 29, 2014
2 parents 8078066 + b448e1d commit a25731a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
11 changes: 10 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
default['consul']['service_mode'] = 'bootstrap'
default['consul']['data_dir'] = '/var/lib/consul'
default['consul']['config_dir'] = '/etc/consul.d'
case node['platform_family']
when 'debian'
default['consul']['etc_config_dir'] = '/etc/default/consul'
when 'rhel'
default['consul']['etc_config_dir'] = '/etc/sysconfig/consul'
else
default['consul']['etc_config_dir'] = '/etc/sysconfig/consul'
end

default['consul']['servers'] = []
default['consul']['init_style'] = 'init' # 'init', 'runit'
default['consul']['service_user'] = 'consul'
Expand All @@ -60,4 +69,4 @@
# UI attributes
default['consul']['client_addr'] = '0.0.0.0'
default['consul']['ui_dir'] = '/var/lib/consul/ui'
default['consul']['serve_ui'] = false
default['consul']['serve_ui'] = false
2 changes: 1 addition & 1 deletion recipes/_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

case node['consul']['init_style']
when 'init'
template '/etc/sysconfig/consul' do
template node['consul']['etc_config_dir'] do
source 'consul-sysconfig.erb'
mode 0755
notifies :create, 'template[/etc/init.d/consul]', :immediately
Expand Down
30 changes: 25 additions & 5 deletions spec/unit/recipes/_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
.with(group: 'root')
.with(mode: 0600)
end
it do
expect(chef_run).to create_template('/etc/init.d/consul')
.with(source: 'consul-init.erb')
.with(mode: 0755)
end
it do
expect(chef_run).to enable_service('consul')
.with(supports: {status: true, restart: true, reload: true})
expect(chef_run).to start_service('consul')
end
end

context 'config on centos' do
let(:chef_run) do
ChefSpec::Runner.new(platform: 'centos', version: '6.3').converge(described_recipe)
end
it do
expect(chef_run).to create_template('/etc/sysconfig/consul')
.with(source: 'consul-sysconfig.erb')
Expand All @@ -26,15 +42,19 @@
it do
expect(chef_run).to render_file('/etc/sysconfig/consul').with_content('GOMAXPROCS=1')
end
end

context 'config on ubuntu' do
let(:chef_run) do
ChefSpec::Runner.new(platform: 'ubuntu', version: '14.04').converge(described_recipe)
end
it do
expect(chef_run).to create_template('/etc/init.d/consul')
.with(source: 'consul-init.erb')
expect(chef_run).to create_template('/etc/default/consul')
.with(source: 'consul-sysconfig.erb')
.with(mode: 0755)
end
it do
expect(chef_run).to enable_service('consul')
.with(supports: {status: true, restart: true, reload: true})
expect(chef_run).to start_service('consul')
expect(chef_run).to render_file('/etc/default/consul').with_content('GOMAXPROCS=1')
end
end

Expand Down
4 changes: 2 additions & 2 deletions templates/default/consul-init.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# * Multi Datacenter
### END INIT INFO

if [ -f /etc/sysconfig/consul ]; then
. /etc/sysconfig/consul
if [ -f <%= node['consul']['etc_config_dir'] %> ]; then
. <%= node['consul']['etc_config_dir'] %>
fi

export GOMAXPROCS=${GOMAXPROCS}
Expand Down

0 comments on commit a25731a

Please sign in to comment.