capistrano-sidekiq 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b43a2e9a957a57fca9cddeb61fe2dab7f38d5d7f
4
- data.tar.gz: bd9d98c7eef3166efa9c1043a06cd138029c3b9a
3
+ metadata.gz: 32f341ab53e9dfdb15b39d595948a85f9004460e
4
+ data.tar.gz: f5ff8d829bc7ae25c517605b61805ba6a79c9abe
5
5
  SHA512:
6
- metadata.gz: 75ded52a6a43fbb98913af4efeaaf5f21ab52e3d6648f48600fda9bf875aa7ba803fc2312e502d3732aa1e5bff82a2210ec778d264603592e657e76860c86623
7
- data.tar.gz: 1fdc6a4f79c26271f8a54d2b251b7da90215c97027e97a3ede44ca354c4263624cebca7873bf9cbbe09e85d8300e08d3ba6a79460257249f0599abac38a0e196
6
+ metadata.gz: 02dd736baaa98223d535075aa3b7ccbb8cbad793b1c309e4206d7b11dfd08ad70d72268ed43b520c5b903612d52463d6b8c543b25f16aca9a09a17e68afaf6bf
7
+ data.tar.gz: e861c2ff9c05b484e4b2c5111bee3b944dfa203d1cdb7b0a4d96c5c34c97a0406fb8d58ebd490bc59d79dddb618cdc7cae53bf9d3d6e7f9e68275310e37e8c65
@@ -0,0 +1,11 @@
1
+ ## Contributors
2
+
3
+ - [Jérémy Lecour] (https://github.com/jlecour)
4
+ - [Fabien Penso] (https://github.com/penso)
5
+ - [Alex Dunae] (https://github.com/alexdunae)
6
+ - [andreygerasimchuk] (https://github.com/andreygerasimchuk)
7
+ - [Saicheg] (https://github.com/Saicheg)
8
+ - [Alex Yakubenko] (https://github.com/alexyakubenko)
9
+ - [Robert Strobl] (https://github.com/rstrobl)
10
+ - [Eurico Doirado] (https://github.com/okoriko)
11
+ - [Huang Bin](https://github.com/hbin)
data/README.md CHANGED
@@ -50,9 +50,10 @@ Configurable options, shown here with defaults:
50
50
  :sidekiq_monit_use_sudo => true
51
51
  :sidekiq_cmd => "#{fetch(:bundle_cmd, "bundle")} exec sidekiq" # Only for capistrano2.5
52
52
  :sidekiqctl_cmd => "#{fetch(:bundle_cmd, "bundle")} exec sidekiqctl" # Only for capistrano2.5
53
+ :sidekiq_user => nil #user to run sidekiq as
53
54
  ```
54
55
 
55
- There is a known bug that prevents sidekiq from starting when pty is true
56
+ There is a known bug that prevents sidekiq from starting when pty is true on Capistrano 3.
56
57
  ```ruby
57
58
  set :pty, false
58
59
  ```
@@ -98,6 +99,7 @@ set :sidekiq_monit_use_sudo, false
98
99
  ```
99
100
 
100
101
  ## Changelog
102
+ - 0.5.4: Add support for custom count of processes per host in monit task @okoriko
101
103
  - 0.5.3: Custom count of processes per each host
102
104
  - 0.5.0: Multiple processes @mrsimo
103
105
  - 0.3.9: Restore daemon flag from Monit template
@@ -122,16 +124,6 @@ set :sidekiq_monit_use_sudo, false
122
124
  - 0.2.3: Added monit tasks (alpha)
123
125
  - 0.2.0: Added sidekiq:rolling_restart - @jlecour
124
126
 
125
- ## Contributors
126
-
127
- - [Jérémy Lecour] (https://github.com/jlecour)
128
- - [Fabien Penso] (https://github.com/penso)
129
- - [Alex Dunae] (https://github.com/alexdunae)
130
- - [andreygerasimchuk] (https://github.com/andreygerasimchuk)
131
- - [Saicheg] (https://github.com/Saicheg)
132
- - [Alex Yakubenko] (https://github.com/alexyakubenko)
133
- - [Robert Strobl] (https://github.com/rstrobl)
134
-
135
127
  ## Contributing
136
128
 
137
129
  1. Fork it
@@ -18,5 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_dependency 'capistrano'
21
- spec.add_dependency 'sidekiq'
21
+ spec.add_dependency 'sidekiq', '>= 3.4'
22
22
  end
@@ -1,5 +1,5 @@
1
1
  if Gem::Specification.find_by_name('capistrano').version >= Gem::Version.new('3.0.0')
2
- load File.expand_path('../tasks/sidekiq.cap', __FILE__)
2
+ load File.expand_path('../tasks/sidekiq.rake', __FILE__)
3
3
  else
4
4
  require_relative 'tasks/capistrano2'
5
5
  end
@@ -1,2 +1,2 @@
1
1
  # load monit tasks
2
- load File.expand_path('../../tasks/monit.cap', __FILE__)
2
+ load File.expand_path('../../tasks/monit.rake', __FILE__)
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Sidekiq
3
- VERSION = '0.5.3'
3
+ VERSION = '0.5.4'
4
4
  end
5
5
  end
@@ -21,6 +21,8 @@ Capistrano::Configuration.instance.load do
21
21
  _cset(:sidekiq_processes) { 1 }
22
22
  _cset(:sidekiq_options_per_process) { nil }
23
23
 
24
+ _cset(:sidekiq_user) { nil }
25
+
24
26
  if fetch(:sidekiq_default_hooks)
25
27
  before 'deploy:update_code', 'sidekiq:quiet'
26
28
  after 'deploy:stop', 'sidekiq:stop'
@@ -32,11 +34,7 @@ Capistrano::Configuration.instance.load do
32
34
  def for_each_process(sidekiq_role, &block)
33
35
  sidekiq_processes = fetch(:"#{ sidekiq_role }_processes") rescue 1
34
36
  sidekiq_processes.times do |idx|
35
- if idx.zero? && sidekiq_processes <= 1
36
- pid_file = fetch(:sidekiq_pid)
37
- else
38
- pid_file = fetch(:sidekiq_pid).gsub(/\.pid$/, "-#{idx}.pid")
39
- end
37
+ pid_file = fetch(:sidekiq_pid).gsub(/\.pid$/, "-#{idx}.pid")
40
38
  yield(pid_file, idx)
41
39
  end
42
40
  end
@@ -56,12 +54,21 @@ Capistrano::Configuration.instance.load do
56
54
  end
57
55
  end
58
56
 
57
+ def run_as(cmd)
58
+ opts = {
59
+ roles: sidekiq_role
60
+ }
61
+ su_user = fetch(:sidekiq_user)
62
+ opts[:shell] = "su - #{su_user}" if su_user
63
+ run cmd, opts
64
+ end
65
+
59
66
  def quiet_process(pid_file, idx, sidekiq_role)
60
- run "if [ -d #{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{current_path} && #{fetch(:sidekiqctl_cmd)} quiet #{pid_file} ; else echo 'Sidekiq is not running'; fi", roles: sidekiq_role
67
+ run_as "if [ -d #{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{current_path} && #{fetch(:sidekiqctl_cmd)} quiet #{pid_file} ; else echo 'Sidekiq is not running'; fi"
61
68
  end
62
69
 
63
70
  def stop_process(pid_file, idx, sidekiq_role)
64
- run "if [ -d #{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{current_path} && #{fetch(:sidekiqctl_cmd)} stop #{pid_file} #{fetch :sidekiq_timeout} ; else echo 'Sidekiq is not running'; fi", roles: sidekiq_role
71
+ run_as "if [ -d #{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{current_path} && #{fetch(:sidekiqctl_cmd)} stop #{pid_file} #{fetch :sidekiq_timeout} ; else echo 'Sidekiq is not running'; fi"
65
72
  end
66
73
 
67
74
  def start_process(pid_file, idx, sidekiq_role)
@@ -90,7 +97,7 @@ Capistrano::Configuration.instance.load do
90
97
  args.push '--daemon'
91
98
  end
92
99
 
93
- run "if [ -d #{current_path} ] && [ ! -f #{pid_file} ] || ! kill -0 `cat #{pid_file}` > /dev/null 2>&1; then cd #{current_path} ; #{fetch(:sidekiq_cmd)} #{args.compact.join(' ')} ; else echo 'Sidekiq is already running'; fi", pty: false, roles: sidekiq_role
100
+ run_as "if [ -d #{current_path} ] && [ ! -f #{pid_file} ] || ! kill -0 `cat #{pid_file}` > /dev/null 2>&1; then cd #{current_path} ; #{fetch(:sidekiq_cmd)} #{args.compact.join(' ')} ; else echo 'Sidekiq is already running'; fi"
94
101
  end
95
102
 
96
103
  desc 'Quiet sidekiq (stop accepting new work)'
@@ -1,9 +1,10 @@
1
1
  namespace :load do
2
2
  task :defaults do
3
- set :sidekiq_monit_conf_dir, -> { '/etc/monit/conf.d' }
4
- set :sidekiq_monit_use_sudo, -> { true }
5
- set :monit_bin, -> { '/usr/bin/monit' }
6
- set :sidekiq_monit_default_hooks, -> { true }
3
+ set :sidekiq_monit_conf_dir, '/etc/monit/conf.d'
4
+ set :sidekiq_monit_use_sudo, true
5
+ set :monit_bin, '/usr/bin/monit'
6
+ set :sidekiq_monit_default_hooks, true
7
+ set :sidekiq_monit_templates_path, 'config/deploy/templates'
7
8
  end
8
9
  end
9
10
 
@@ -118,6 +119,10 @@ namespace :sidekiq do
118
119
  end
119
120
  end
120
121
 
122
+ def sidekiq_options_per_process
123
+ fetch(:sidekiq_options_per_process) || []
124
+ end
125
+
121
126
  def sudo_if_needed(command)
122
127
  send(use_sudo? ? :sudo : :execute, command)
123
128
  end
@@ -9,11 +9,13 @@ namespace :load do
9
9
  set :sidekiq_role, -> { :app }
10
10
  set :sidekiq_processes, -> { 1 }
11
11
  set :sidekiq_options_per_process, -> { nil }
12
- # Rbenv and RVM integration
12
+ set :sidekiq_user, -> { nil }
13
+ # Rbenv, Chruby, and RVM integration
13
14
  set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(sidekiq sidekiqctl))
14
15
  set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(sidekiq sidekiqctl))
15
-
16
- set :sidekiq_monit_templates_path, -> { 'config/deploy/templates' }
16
+ set :chruby_map_bins, fetch(:chruby_map_bins).to_a.concat(%w{ sidekiq sidekiqctl })
17
+ # Bundler integration
18
+ set :bundle_bins, fetch(:bundle_bins).to_a.concat(%w(sidekiq sidekiqctl))
17
19
  end
18
20
  end
19
21
 
@@ -44,9 +46,7 @@ namespace :sidekiq do
44
46
  next unless host.roles.include?(role)
45
47
  processes = fetch(:"#{ role }_processes") || fetch(:sidekiq_processes)
46
48
  processes.times do |idx|
47
- pids.push (idx.zero? && processes <= 1) ?
48
- fetch(:sidekiq_pid) :
49
- fetch(:sidekiq_pid).gsub(/\.pid$/, "-#{idx}.pid")
49
+ pids.push fetch(:sidekiq_pid).gsub(/\.pid$/, "-#{idx}.pid")
50
50
  end
51
51
  end
52
52
 
@@ -66,10 +66,10 @@ namespace :sidekiq do
66
66
  if fetch(:sidekiq_use_signals)
67
67
  background "kill -TERM `cat #{pid_file}`"
68
68
  else
69
- background :bundle, :exec, :sidekiqctl, 'stop', "#{pid_file}", fetch(:sidekiq_timeout)
69
+ background :sidekiqctl, 'stop', "#{pid_file}", fetch(:sidekiq_timeout)
70
70
  end
71
71
  else
72
- execute :bundle, :exec, :sidekiqctl, 'stop', "#{pid_file}", fetch(:sidekiq_timeout)
72
+ execute :sidekiqctl, 'stop', "#{pid_file}", fetch(:sidekiq_timeout)
73
73
  end
74
74
  end
75
75
 
@@ -78,7 +78,7 @@ namespace :sidekiq do
78
78
  background "kill -USR1 `cat #{pid_file}`"
79
79
  else
80
80
  begin
81
- execute :bundle, :exec, :sidekiqctl, 'quiet', "#{pid_file}"
81
+ execute :sidekiqctl, 'quiet', "#{pid_file}"
82
82
  rescue SSHKit::Command::Failed
83
83
  # If gems are not installed eq(first deploy) and sidekiq_default_hooks as active
84
84
  warn 'sidekiqctl not found (ignore if this is the first deploy)'
@@ -113,9 +113,9 @@ namespace :sidekiq do
113
113
  end
114
114
 
115
115
  if fetch(:start_sidekiq_in_background, fetch(:sidekiq_run_in_background))
116
- background :bundle, :exec, :sidekiq, args.compact.join(' ')
116
+ background :sidekiq, args.compact.join(' ')
117
117
  else
118
- execute :bundle, :exec, :sidekiq, args.compact.join(' ')
118
+ execute :sidekiq, args.compact.join(' ')
119
119
  end
120
120
  end
121
121
 
@@ -129,10 +129,12 @@ namespace :sidekiq do
129
129
  desc 'Quiet sidekiq (stop processing new tasks)'
130
130
  task :quiet do
131
131
  on roles fetch(:sidekiq_role) do
132
- if test("[ -d #{release_path} ]") # fixes #11
133
- for_each_process(true) do |pid_file, idx|
134
- if pid_process_exists?(pid_file)
135
- quiet_sidekiq(pid_file)
132
+ switch_user do
133
+ if test("[ -d #{release_path} ]") # fixes #11
134
+ for_each_process(true) do |pid_file, idx|
135
+ if pid_process_exists?(pid_file)
136
+ quiet_sidekiq(pid_file)
137
+ end
136
138
  end
137
139
  end
138
140
  end
@@ -142,10 +144,12 @@ namespace :sidekiq do
142
144
  desc 'Stop sidekiq'
143
145
  task :stop do
144
146
  on roles fetch(:sidekiq_role) do
145
- if test("[ -d #{release_path} ]")
146
- for_each_process(true) do |pid_file, idx|
147
- if pid_process_exists?(pid_file)
148
- stop_sidekiq(pid_file)
147
+ switch_user do
148
+ if test("[ -d #{release_path} ]")
149
+ for_each_process(true) do |pid_file, idx|
150
+ if pid_process_exists?(pid_file)
151
+ stop_sidekiq(pid_file)
152
+ end
149
153
  end
150
154
  end
151
155
  end
@@ -155,8 +159,10 @@ namespace :sidekiq do
155
159
  desc 'Start sidekiq'
156
160
  task :start do
157
161
  on roles fetch(:sidekiq_role) do
158
- for_each_process do |pid_file, idx|
159
- start_sidekiq(pid_file, idx) unless pid_process_exists?(pid_file)
162
+ switch_user do
163
+ for_each_process do |pid_file, idx|
164
+ start_sidekiq(pid_file, idx) unless pid_process_exists?(pid_file)
165
+ end
160
166
  end
161
167
  end
162
168
  end
@@ -170,11 +176,13 @@ namespace :sidekiq do
170
176
  desc 'Rolling-restart sidekiq'
171
177
  task :rolling_restart do
172
178
  on roles fetch(:sidekiq_role) do
173
- for_each_process(true) do |pid_file, idx|
174
- if pid_process_exists?(pid_file)
175
- stop_sidekiq(pid_file)
179
+ switch_user do
180
+ for_each_process(true) do |pid_file, idx|
181
+ if pid_process_exists?(pid_file)
182
+ stop_sidekiq(pid_file)
183
+ end
184
+ start_sidekiq(pid_file, idx)
176
185
  end
177
- start_sidekiq(pid_file, idx)
178
186
  end
179
187
  end
180
188
  end
@@ -182,9 +190,11 @@ namespace :sidekiq do
182
190
  # Delete any pid file not in use
183
191
  task :cleanup do
184
192
  on roles fetch(:sidekiq_role) do
185
- for_each_process do |pid_file, idx|
186
- if pid_file_exists?(pid_file)
187
- execute "rm #{pid_file}" unless pid_process_exists?(pid_file)
193
+ switch_user do
194
+ for_each_process do |pid_file, idx|
195
+ if pid_file_exists?(pid_file)
196
+ execute "rm #{pid_file}" unless pid_process_exists?(pid_file)
197
+ end
188
198
  end
189
199
  end
190
200
  end
@@ -195,14 +205,27 @@ namespace :sidekiq do
195
205
  task :respawn do
196
206
  invoke 'sidekiq:cleanup'
197
207
  on roles fetch(:sidekiq_role) do
198
- for_each_process do |pid_file, idx|
199
- unless pid_file_exists?(pid_file)
200
- start_sidekiq(pid_file, idx)
208
+ switch_user do
209
+ for_each_process do |pid_file, idx|
210
+ unless pid_file_exists?(pid_file)
211
+ start_sidekiq(pid_file, idx)
212
+ end
201
213
  end
202
214
  end
203
215
  end
204
216
  end
205
217
 
218
+ def switch_user(&block)
219
+ su_user = fetch(:sidekiq_user)
220
+ if su_user
221
+ as su_user do
222
+ yield
223
+ end
224
+ end
225
+
226
+ yield
227
+ end
228
+
206
229
  def upload_sidekiq_template(from, to, role)
207
230
  template = sidekiq_template(from, role)
208
231
  upload!(StringIO.new(ERB.new(template).result(binding)), to)
@@ -2,9 +2,9 @@
2
2
  <% processes_pids.each_with_index do |pid_file, idx| %>
3
3
  check process <%= sidekiq_service_name(idx) %>
4
4
  with pidfile "<%= pid_file %>"
5
- start program = "/bin/su - <%= @role.user %> -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec sidekiq <%= sidekiq_config %> --index <%= idx %> --pidfile <%= pid_file %> --environment <%= fetch(:sidekiq_env) %> <%= sidekiq_concurrency %> <%= sidekiq_logfile %> <%= sidekiq_queues %> -d'" with timeout 30 seconds
5
+ start program = "/bin/su - <%= @role.user %> -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:sidekiq] %> <%= sidekiq_config %> --index <%= idx %> --pidfile <%= pid_file %> --environment <%= fetch(:sidekiq_env) %> <%= sidekiq_concurrency %> <%= sidekiq_logfile %> <%= sidekiq_queues %> <%= sidekiq_options_per_process[idx] %> -d'" with timeout 30 seconds
6
6
 
7
- stop program = "/bin/su - <%= @role.user %> -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec sidekiqctl stop <%= pid_file %>'" with timeout <%= fetch(:sidekiq_timeout).to_i + 10 %> seconds
7
+ stop program = "/bin/su - <%= @role.user %> -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:sidekiqctl] %> stop <%= pid_file %>'" with timeout <%= fetch(:sidekiq_timeout).to_i + 10 %> seconds
8
8
  group <%= fetch(:sidekiq_monit_group, fetch(:application)) %>-sidekiq
9
9
 
10
10
  <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3.4'
41
41
  description: Sidekiq integration for Capistrano
42
42
  email:
43
43
  - terminale@gmail.com
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - CONTRIBUTORS.md
49
50
  - Gemfile
50
51
  - LICENSE.txt
51
52
  - README.md
@@ -56,8 +57,8 @@ files:
56
57
  - lib/capistrano/sidekiq/monit.rb
57
58
  - lib/capistrano/sidekiq/version.rb
58
59
  - lib/capistrano/tasks/capistrano2.rb
59
- - lib/capistrano/tasks/monit.cap
60
- - lib/capistrano/tasks/sidekiq.cap
60
+ - lib/capistrano/tasks/monit.rake
61
+ - lib/capistrano/tasks/sidekiq.rake
61
62
  - lib/generators/capistrano/sidekiq/monit/template_generator.rb
62
63
  - lib/generators/capistrano/sidekiq/monit/templates/sidekiq_monit.conf.erb
63
64
  homepage: https://github.com/seuros/capistrano-sidekiq
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  version: '0'
81
82
  requirements: []
82
83
  rubyforge_project:
83
- rubygems_version: 2.4.5
84
+ rubygems_version: 2.4.8
84
85
  signing_key:
85
86
  specification_version: 4
86
87
  summary: Sidekiq integration for Capistrano