Skip to content

Commit

Permalink
add customizing the monit templates for sidekiq
Browse files Browse the repository at this point in the history
  • Loading branch information
SammyLin committed Dec 17, 2014
1 parent a5c807b commit 2aa697a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Configurable options, shown here with defaults:
:sidekiq_role => :app
:sidekiq_processes => 1
:sidekiq_concurrency => nil
:sidekiq_monit_templates_path => 'config/deploy/templates'
:sidekiq_cmd => "#{fetch(:bundle_cmd, "bundle")} exec sidekiq" # Only for capistrano2.5
:sidekiqctl_cmd => "#{fetch(:bundle_cmd, "bundle")} exec sidekiqctl" # Only for capistrano2.5
```
Expand All @@ -53,6 +54,16 @@ There is a known bug that prevents sidekiq from starting when pty is true
```ruby
set :pty, false
```

## Customizing the monit sidekiq templates

If you need change some config in redactor, you can

```
bundle exec rails generate capistrano:sidekiq:monit:template
```

## Changelog
- 0.3.9: Restore daemon flag from Monit template
- 0.3.8:
Expand All @@ -64,7 +75,7 @@ set :pty, false
- 0.3.5: Added :sidekiq_tag for capistrano2 @OscarBarrett
- 0.3.4: fix bug in sidekiq:start for capistrano 2 task
- 0.3.3: sidekiq:restart after deploy:restart added to default hooks
- 0.3.2: :sidekiq_queue accept an array
- 0.3.2: :sidekiq_queue accept an array
- 0.3.1: Fix logs @rottman, add concurrency option support @ungsophy
- 0.3.0: Fix monit task @andreygerasimchuk
- 0.2.9: Check if current directory exist @alexdunae
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano/tasks/monit.cap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace :sidekiq do
task :config do
on roles(fetch(:sidekiq_role)) do |role|
@role = role
template_sidekiq 'sidekiq_monit.conf', "#{fetch(:tmp_dir)}/monit.conf", @role
template_sidekiq 'sidekiq_monit', "#{fetch(:tmp_dir)}/monit.conf", @role
sudo "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:sidekiq_monit_conf_dir)}/#{sidekiq_service_name}.conf"
end
end
Expand Down
20 changes: 12 additions & 8 deletions lib/capistrano/tasks/sidekiq.cap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace :load do
# Rbenv and RVM integration
set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(sidekiq sidekiqctl))
set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(sidekiq sidekiqctl))

set :sidekiq_monit_templates_path, -> { 'config/deploy/templates' }
end
end

Expand Down Expand Up @@ -195,14 +197,16 @@ namespace :sidekiq do

def template_sidekiq(from, to, role)
[
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}-#{fetch(:stage)}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}-#{fetch(:stage)}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}.rb.erb"),
File.join('lib', 'capistrano', 'templates', "#{from}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}.erb"),
File.expand_path("../../templates/#{from}.rb.erb", __FILE__),
File.expand_path("../../templates/#{from}.erb", __FILE__)
"#{fetch(:sidekiq_monit_templates_path)}/#{from}.erb",
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}-#{fetch(:stage)}.conf.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}-#{fetch(:stage)}.conf.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}.conf.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}-#{fetch(:stage)}.conf.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}.conf.rb.erb"),
File.join('lib', 'capistrano', 'templates', "#{from}.conf.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}.conf.erb"),
File.expand_path("../../../generators/capistrano/sidekiq/monit/templates/#{from}.conf.rb.erb", __FILE__),
File.expand_path("../../../generators/capistrano/sidekiq/monit/templates/#{from}.conf.erb", __FILE__)
].each do |path|
if File.file?(path)
erb = File.read(path)
Expand Down
21 changes: 21 additions & 0 deletions lib/generators/capistrano/sidekiq/monit/template_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Capistrano
module Sidekiq
module Monit
module Generators
class TemplateGenerator < Rails::Generators::Base

desc "Create local monitrc.erb, and erb files for monitored processes for customization"
source_root File.expand_path('../templates', __FILE__)
argument :templates_path, type: :string,
default: "config/deploy/templates",
banner: "path to templates"

def copy_template
copy_file "sidekiq_monit.conf.erb", "#{templates_path}/sidekiq_monit.erb"
end

end
end
end
end
end

0 comments on commit 2aa697a

Please sign in to comment.