Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set correct etc config directory for default consul behavior #68

Merged
merged 2 commits into from
Oct 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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