Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
fix(worker): quieting and stopping sidekiq
Browse files Browse the repository at this point in the history
  • Loading branch information
betesh authored and ajgon committed May 11, 2019
1 parent 59198b9 commit efc1231
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
16 changes: 8 additions & 8 deletions libraries/drivers_worker_sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ def quiet_sidekiq
(1..process_count).each do |process_number|
Chef::Log.info("Quiet Sidekiq process if exists: no. #{process_number}")

context.execute(
"/bin/su - #{node['deployer']['user']} -c \"ps -ax | grep 'bundle exec sidekiq' | " \
"grep sidekiq_#{process_number}.yml | grep -v grep | awk '{print $1}' | xargs kill -TSTP\""
)
context.execute(send_signal_to_sidekiq(process_number, :TSTP))
end
end

Expand All @@ -61,13 +58,16 @@ def stop_sidekiq
timeout = (out[:config]['timeout'] || 8).to_i
Chef::Log.info("Stop Sidekiq process if exists: no. #{process_number}")

context.execute(
"timeout #{timeout} /bin/su - #{node['deployer']['user']} -c \"ps -ax | grep 'bundle exec sidekiq' | " \
"grep sidekiq_#{process_number}.yml | grep -v grep | awk '{print $1}' | xargs kill -TERM\""
)
context.execute("timeout #{timeout} #{send_signal_to_sidekiq(process_number)}")
end
end

def send_signal_to_sidekiq(process_number, signal = nil)
"/bin/su - #{node['deployer']['user']} -c \"ps -ax | grep 'bundle exec sidekiq' | " \
"grep sidekiq_#{process_number}.yml | grep -v grep | awk '{print \\$1}' | " \
"xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill#{" -#{signal}" if signal}\""
end

def configuration
JSON.parse(out[:config].to_json, symbolize_names: true)
end
Expand Down
20 changes: 12 additions & 8 deletions spec/unit/recipes/configure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,9 @@
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'stop program = "/bin/su - deploy -c \"ps -ax | grep \'bundle exec sidekiq\' | grep sidekiq_1.yml | ' \
'grep -v grep | awk \'{print $1}\' | xargs kill\"" with timeout 8 seconds'
'stop program = "/bin/su - deploy -c \'ps -ax | grep "bundle exec sidekiq" | grep sidekiq_1.yml | ' \
'grep -v grep | awk "{print \$1}" | xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill\'" ' \
'with timeout 8 seconds'
)
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
Expand All @@ -403,8 +404,9 @@
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'stop program = "/bin/su - deploy -c \"ps -ax | grep \'bundle exec sidekiq\' | grep sidekiq_2.yml | ' \
'grep -v grep | awk \'{print $1}\' | xargs kill\"" with timeout 8 seconds'
'stop program = "/bin/su - deploy -c \'ps -ax | grep "bundle exec sidekiq" | grep sidekiq_2.yml | ' \
'grep -v grep | awk "{print \$1}" | xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill\'" ' \
'with timeout 8 seconds'
)
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
Expand All @@ -431,8 +433,9 @@
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'stop program = "/bin/su - deploy -c \"ps -ax | grep \'bundle exec sidekiq\' | grep sidekiq_1.yml | ' \
'grep -v grep | awk \'{print $1}\' | xargs kill\"" with timeout 8 seconds'
'stop program = "/bin/su - deploy -c \'ps -ax | grep "bundle exec sidekiq" | grep sidekiq_1.yml | ' \
'grep -v grep | awk "{print \$1}" | xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill\'" ' \
'with timeout 8 seconds'
)
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
Expand All @@ -449,8 +452,9 @@
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'stop program = "/bin/su - deploy -c \"ps -ax | grep \'bundle exec sidekiq\' | grep sidekiq_2.yml | ' \
'grep -v grep | awk \'{print $1}\' | xargs kill\"" with timeout 8 seconds'
'stop program = "/bin/su - deploy -c \'ps -ax | grep "bundle exec sidekiq" | grep sidekiq_2.yml | ' \
'grep -v grep | awk "{print \$1}" | xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill\'" ' \
'with timeout 8 seconds'
)
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
Expand Down
12 changes: 8 additions & 4 deletions spec/unit/recipes/shutdown_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
expect(chef_run).to(
run_execute(
'/bin/su - deploy -c "ps -ax | grep \'bundle exec sidekiq\' | ' \
'grep sidekiq_1.yml | grep -v grep | awk \'{print $1}\' | xargs kill -TSTP"'
'grep sidekiq_1.yml | grep -v grep | awk \'{print \\$1}\' | ' \
'xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill -TSTP"'
)
)
expect(chef_run).to(
run_execute(
'/bin/su - deploy -c "ps -ax | grep \'bundle exec sidekiq\' | ' \
'grep sidekiq_2.yml | grep -v grep | awk \'{print $1}\' | xargs kill -TSTP"'
'grep sidekiq_2.yml | grep -v grep | awk \'{print \\$1}\' | ' \
'xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill -TSTP"'
)
)
end
Expand All @@ -48,13 +50,15 @@
expect(chef_run).to(
run_execute(
'timeout 8 /bin/su - deploy -c "ps -ax | grep \'bundle exec sidekiq\' | ' \
'grep sidekiq_1.yml | grep -v grep | awk \'{print $1}\' | xargs kill -TERM"'
'grep sidekiq_1.yml | grep -v grep | awk \'{print \\$1}\' | ' \
'xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill"'
)
)
expect(chef_run).to(
run_execute(
'timeout 8 /bin/su - deploy -c "ps -ax | grep \'bundle exec sidekiq\' | ' \
'grep sidekiq_2.yml | grep -v grep | awk \'{print $1}\' | xargs kill -TERM"'
'grep sidekiq_2.yml | grep -v grep | awk \'{print \\$1}\' | ' \
'xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill"'
)
)
end
Expand Down
2 changes: 1 addition & 1 deletion templates/default/sidekiq.monitrc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

check process sidekiq_<%= identifier.to_s %> matching "bundle exec sidekiq.*/sidekiq_<%= n+1 %>.yml"
start program = "/bin/su - <%= node['deployer']['user'] %> -c 'cd <%= File.join(@deploy_to, 'current') %> && <%= @environment.map { |k, v| "#{k}=\"#{v}\"" }.join(' ') %> bundle exec sidekiq -C <%= conf_file.to_s %><%= to_require.to_s %> <%= syslog.to_s %>'" with timeout 90 seconds
stop program = "/bin/su - <%= node['deployer']['user'] %> -c \"ps -ax | grep 'bundle exec sidekiq' | grep sidekiq_<%= n+1 %>.yml | grep -v grep | awk '{print $1}' | xargs kill\"" with timeout <%= timeout %> seconds
stop program = "/bin/su - <%= node['deployer']['user'] %> -c 'ps -ax | grep "bundle exec sidekiq" | grep sidekiq_<%= n+1 %>.yml | grep -v grep | awk "{print \$1}" | xargs --no-run-if-empty pgrep -P | xargs --no-run-if-empty kill'" with timeout <%= timeout %> seconds
group sidekiq_<%= @application.to_s %>_group

<% end %>

0 comments on commit efc1231

Please sign in to comment.