-
Notifications
You must be signed in to change notification settings - Fork 269
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
Fixes #34824 - properly restart foreman when puma config changed #1045
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a lot simpler than what I thought it would be
how about a test to prevent us from breaking it in the future?
a test of what? the before relationship? That I can add. What I don't really know is how to test the actual "foreman is running with the expected puma settings". |
It's a little rough maybe but you could do something like require 'spec_helper_acceptance'
describe 'configures puma worker count', :order => :defined do
context 'initial configuration with 2 puma workers' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'foreman':
foreman_service_puma_workers => 2,
}
PUPPET
end
end
describe service("foreman") do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
[0,1].each do |i|
describe command("ps aux | grep -v grep | grep \"puma: cluster worker #{i}\"") do
its(:exit_status) { is_expected.to eq 0 }
end
end
describe command('ps aux | grep -v grep | grep "puma: cluster worker 2"') do
its(:exit_status) { is_expected.to eq 1 }
end
end
context 'reconfigure to use 1 puma worker and restart foreman.service' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'foreman':
foreman_service_puma_workers => 1,
}
PUPPET
end
end
describe service("foreman") do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
describe command('ps aux | grep -v grep | grep "puma: cluster worker 0"') do
its(:exit_status) { is_expected.to eq 0 }
end
[1,2].each do |i|
describe command("ps aux | grep -v grep | grep \"puma: cluster worker #{i}\"") do
its(:exit_status) { is_expected.to eq 1 }
end
end
end
end |
I'll try tomorrow, thanks |
OK, cool. And I suppose a cleaner implementation might be possible with https://github.com/mizzy/serverspec/blob/master/lib/serverspec/type/process.rb |
really rspec?! |
Lots of options, there is also |
4d36696
to
d2f826b
Compare
2e8ec7f
to
9d83dcc
Compare
@ehelms @wbclark what do you find more readable? describe command('ps aux | grep -v grep | grep -c "puma: cluster worker"') do
its('stdout.to_i') { is_expected.to eq 1 }
end or describe process('puma: cluster worker') do
its(:count) { is_expected.to eq 1 }
end Myself, I prefer What should probably work is describe process('rails') do
it { is_expected.to be_running }
# 1 worker + 1 scheduler = 2 processes
its(:count) { is_expected.to eq 2 }
end Edit: turns out it does not work, as now the |
The use of |
we need to restart foreman.service *before* a (possible) restart of foreman.socket, as the later *also* does restart foreman.service which leads to foreman.socket being *started* instead of *restarted* /Service[foreman.socket]: Starting to evaluate the resource (2265 of 2522) Executing: '/bin/systemctl is-active -- foreman.socket' Executing: '/bin/systemctl restart -- foreman.socket' /Service[foreman]: Starting to evaluate the resource (2266 of 2522) Executing: '/bin/systemctl is-active -- foreman' Executing: '/bin/systemctl show --property=NeedDaemonReload -- foreman' Executing: '/bin/systemctl daemon-reload' Executing: '/bin/systemctl unmask -- foreman' Executing: '/bin/systemctl start -- foreman' Executing: '/bin/systemctl is-enabled -- foreman' /Stage[main]/Foreman::Service/Service[foreman]/ensure: ensure changed 'stopped' to 'running' But in this case the now running foreman.service didn't see the changes to the service file that daemon-reload would have loaded.
Updated then! |
Ubuntu 🙄 |
\o/ |
Thanks @wbclark for the test suggestions! That worked perfectly. |
we need to restart foreman.service before a (possible) restart of
foreman.socket, as the later also does restart foreman.service which
leads to foreman.socket being started instead of restarted
But in this case the now running foreman.service didn't see the changes
to the service file that daemon-reload would have loaded.