Skip to content

Commit

Permalink
Merge pull request #71 from wilreichert/upstart
Browse files Browse the repository at this point in the history
add upstart init
  • Loading branch information
johnbellone committed Nov 14, 2014
2 parents a556de5 + c666027 commit 111a581
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
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")
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

0 comments on commit 111a581

Please sign in to comment.