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

add upstart init #71

Merged
merged 3 commits into from
Nov 14, 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
16 changes: 13 additions & 3 deletions recipes/_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,22 @@

case node['consul']['init_style']
when 'init'
if platform?("ubuntu")
init_file = '/etc/init/consul.conf'
init_tmpl = 'consul.conf.erb'
else
init_file = '/etc/init.d/consul'
init_tmpl = 'consul-init.erb'
end

template node['consul']['etc_config_dir'] do
source 'consul-sysconfig.erb'
mode 0755
notifies :create, 'template[/etc/init.d/consul]', :immediately
notifies :create, "template[#{init_file}]", :immediately
end
template '/etc/init.d/consul' do
source 'consul-init.erb'

template init_file do
source init_tmpl
mode 0755
variables(
consul_binary: "#{node['consul']['install_dir']}/consul",
Expand All @@ -149,6 +158,7 @@
end

service 'consul' do
provider Chef::Provider::Service::Upstart if platform?("ubuntu")

This comment was marked as outdated.

This comment was marked as outdated.

supports status: true, restart: true, reload: true
action [:enable, :start]
subscribes :restart, "file[#{consul_config_filename}", :delayed
Expand Down
19 changes: 12 additions & 7 deletions spec/unit/recipes/_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +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
context 'init 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/init.d/consul')
.with(source: 'consul-init.erb')
.with(mode: 0755)
end
it do
expect(chef_run).to create_template('/etc/sysconfig/consul')
.with(source: 'consul-sysconfig.erb')
Expand All @@ -44,10 +44,15 @@
end
end

context 'config on ubuntu' do
context 'init 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/consul.conf')
.with(source: 'consul.conf.erb')
.with(mode: 0755)
end
it do
expect(chef_run).to create_template('/etc/default/consul')
.with(source: 'consul-sysconfig.erb')
Expand Down
20 changes: 20 additions & 0 deletions templates/default/consul.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
description "Consul Service Discovery Platform"

emits consul-up

start on runlevel [2345]
stop on runlevel [!2345]

script
if [ -f <%= node['consul']['etc_config_dir'] %> ]; then
. <%= node['consul']['etc_config_dir'] %>
fi
export GOMAXPROCS=${GOMAXPROCS}
CMD="<%= @consul_binary %> agent -config-dir <%= @config_dir %>"
LOGFILE="/var/log/consul.log"
exec $CMD >> "$LOGFILE"
end script

post-start exec initctl emit consul-up

kill signal INT