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

Added post-start script to upstart config to delay service started event until consul ready to serve requests #320

Merged
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
1 change: 1 addition & 0 deletions libraries/consul_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def service_options(service)
service.restart_on_update(false)
service.options(:systemd, template: 'consul:systemd.service.erb')
service.options(:sysvinit, template: 'consul:sysvinit.service.erb')
service.options(:upstart, template: 'consul:upstart.service.erb', executable: new_resource.program)

if node.platform_family?('rhel') && node.platform_version.to_i == 6
service.provider(:sysvinit)
Expand Down
52 changes: 52 additions & 0 deletions templates/default/upstart.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# <%= @name %> generated by poise-service for <%= @new_resource.to_s %>

description "<%= @name %>"

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

respawn
respawn limit 10 5
umask 022
chdir <%= @directory %>
<%- @environment.each do |key, val| -%>
env <%= key %>="<%= val %>"
<%- end -%>
<%- if @upstart_features[:setuid] -%>
setuid <%= @user %>
<%- end -%>
<%- if @upstart_features[:kill_signal] -%>
kill signal <%= @stop_signal %>
<%- end -%>
<%- if @upstart_features[:reload_signal] -%>
reload signal <%= @reload_signal %>
<%- end -%>

<%- if @upstart_features[:setuid] -%>
exec <%= @command %>
<%- else -%>
script
exec /opt/chef/embedded/bin/ruby <<EOH
require 'etc'
ent = Etc.getpwnam(<%= @user.inspect %>)
if Process.euid != ent.uid || Process.egid != ent.gid
Process.initgroups(ent.name, ent.gid)
Process::GID.change_privilege(ent.gid) if Process.egid != ent.gid
Process::UID.change_privilege(ent.uid) if Process.euid != ent.uid
end
ENV["HOME"] = Dir.home(<%= @user.inspect %>) rescue nil
exec(*<%= Shellwords.split(@command).inspect %>)
EOH
end script
<%- end -%>
<%- if !@upstart_features[:kill_signal] && @stop_signal != 'TERM' -%>
pre-stop script
PID=`initctl status <%= @name %> | sed 's/^.*process \([0-9]*\)$/\1/'`
if [ -n "$PID" ]; then
kill -<%= @stop_signal %> "$PID"
fi
end script
<%- end -%>
post-start script
while ! <%= @options[:executable] %> info ; sleep 1; done
end script
17 changes: 16 additions & 1 deletion test/integration/default/serverspec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'spec_helper'

describe file('/opt/consul/0.6.4/consul') do
consul_version = '0.6.4'
consul_executable = "/opt/consul/#{consul_version}/consul"

describe file(consul_executable) do
it { should be_file }
it { should be_executable }
end
Expand Down Expand Up @@ -61,3 +64,15 @@

it { should be_mode 755 }
end

if os[:family] == 'ubuntu'
describe file('/etc/init/consul.conf' ) do
its(:content) do
should include(<<-EOT)
post-start script
while ! #{consul_executable} info ; sleep 1; done
end script
EOT
end
end
end