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

Commit

Permalink
fix(worker): adapted monit config for sidekiq 6.x
Browse files Browse the repository at this point in the history
Fixes #215
  • Loading branch information
ajgon committed Apr 10, 2019
1 parent c02af02 commit 4a58654
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ guide in [documentation](http://opsworks-ruby.readthedocs.io/en/latest/index.htm

## Development

You can either install eveyrthing locally using [rvm](https://rvm.io/) and [pip](https://pypi.python.org/pypi/pip)
You can either install everything locally using [rvm](https://rvm.io/) and [pip](https://pypi.python.org/pypi/pip)
or use the Docker container which includes all necessary dependencies inside it.

### Build documentation
Expand Down
48 changes: 12 additions & 36 deletions spec/unit/recipes/configure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,51 +372,39 @@
expect(chef_run_rhel).to create_template("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content('check process sidekiq_dummy_project-1')
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content('with pidfile /run/lock/dummy_project/sidekiq_dummy_project-1.pid')
.with_content('check process sidekiq_dummy_project-1 matching "bundle exec sidekiq.*/sidekiq_1.yml"')
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" bundle exec sidekiq ' \
'-C /srv/www/dummy_project/shared/config/sidekiq_1.yml ' \
'-i 0 ' \
'-P /run/lock/dummy_project/sidekiq_dummy_project-1.pid ' \
'-r /srv/www/dummy_project/current/lorem_ipsum.rb 2>&1 ' \
'| logger -t sidekiq-dummy_project-1\'" with timeout 90 seconds'
)
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'stop program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" bundle exec sidekiqctl stop ' \
'/run/lock/dummy_project/sidekiq_dummy_project-1.pid 8\'" with timeout 18 seconds'
'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'
)
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content('check process sidekiq_dummy_project-2')
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content('with pidfile /run/lock/dummy_project/sidekiq_dummy_project-2.pid')
.with_content('check process sidekiq_dummy_project-2 matching "bundle exec sidekiq.*/sidekiq_2.yml"')
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" bundle exec sidekiq ' \
'-C /srv/www/dummy_project/shared/config/sidekiq_2.yml ' \
'-i 1 ' \
'-P /run/lock/dummy_project/sidekiq_dummy_project-2.pid ' \
'-r /srv/www/dummy_project/current/lorem_ipsum.rb 2>&1 ' \
'| logger -t sidekiq-dummy_project-2\'" with timeout 90 seconds'
)
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'stop program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" bundle exec sidekiqctl stop ' \
'/run/lock/dummy_project/sidekiq_dummy_project-2.pid 8\'" with timeout 18 seconds'
'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'
)
expect(chef_run_rhel)
.to render_file("/etc/monit.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
Expand All @@ -430,51 +418,39 @@
expect(chef_run).to create_template("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content('check process sidekiq_dummy_project-1')
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content('with pidfile /run/lock/dummy_project/sidekiq_dummy_project-1.pid')
.with_content('check process sidekiq_dummy_project-1 matching "bundle exec sidekiq.*/sidekiq_1.yml"')
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" bundle exec sidekiq ' \
'-C /srv/www/dummy_project/shared/config/sidekiq_1.yml ' \
'-i 0 ' \
'-P /run/lock/dummy_project/sidekiq_dummy_project-1.pid ' \
'-r /srv/www/dummy_project/current/lorem_ipsum.rb 2>&1 ' \
'| logger -t sidekiq-dummy_project-1\'" with timeout 90 seconds'
)
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'stop program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" bundle exec sidekiqctl stop ' \
'/run/lock/dummy_project/sidekiq_dummy_project-1.pid 8\'" with timeout 18 seconds'
'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'
)
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content('check process sidekiq_dummy_project-2')
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content('with pidfile /run/lock/dummy_project/sidekiq_dummy_project-2.pid')
.with_content('check process sidekiq_dummy_project-2 matching "bundle exec sidekiq.*/sidekiq_2.yml"')
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" bundle exec sidekiq ' \
'-C /srv/www/dummy_project/shared/config/sidekiq_2.yml ' \
'-i 1 ' \
'-P /run/lock/dummy_project/sidekiq_dummy_project-2.pid ' \
'-r /srv/www/dummy_project/current/lorem_ipsum.rb 2>&1 ' \
'| logger -t sidekiq-dummy_project-2\'" with timeout 90 seconds'
)
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
.with_content(
'stop program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" RAILS_ENV="staging" HOME="/home/deploy" USER="deploy" bundle exec sidekiqctl stop ' \
'/run/lock/dummy_project/sidekiq_dummy_project-2.pid 8\'" with timeout 18 seconds'
'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'
)
expect(chef_run)
.to render_file("/etc/monit/conf.d/sidekiq_#{aws_opsworks_app['shortname']}.monitrc")
Expand Down
8 changes: 3 additions & 5 deletions templates/default/sidekiq.monitrc.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<% ([@out[:process_count].to_i || 1].max).times do |n| %>
<% identifier = "#{@application}-#{n+1}" %>
<% conf_file = "#{@deploy_to}/shared/config/sidekiq_#{n+1}.yml" %>
<% pid_file = "/run/lock/#{@app_shortname}/sidekiq_#{identifier}.pid" %>
<% syslog = !!@out[:syslog] ? "2>&1 | logger -t sidekiq-#{identifier}" : '' %>
<% to_require = @out[:require].present? ? " -r #{File.join(@deploy_to, 'current', @out[:require])}" : '' %>
<% timeout = (@out[:config]['timeout'] || 8).to_i %>

check process sidekiq_<%= identifier.to_s %>
with pidfile <%= pid_file.to_s %>
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 %> -i <%= n %> -P <%= pid_file.to_s %><%= to_require.to_s %> <%= syslog.to_s %>'" with timeout 90 seconds
stop program = "/bin/su - <%= node['deployer']['user'] %> -c 'cd <%= File.join(@deploy_to, 'current') %> && <%= @environment.map { |k, v| "#{k}=\"#{v}\"" }.join(' ') %> bundle exec sidekiqctl stop <%= pid_file %> <%= timeout %>'" with timeout <%= timeout + 10 %> seconds
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
group sidekiq_<%= @application.to_s %>_group

<% end %>

0 comments on commit 4a58654

Please sign in to comment.