capistrano-sidekiq 0.1.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/capistrano/sidekiq/monit.rb +2 -0
- data/lib/capistrano/sidekiq/version.rb +1 -1
- data/lib/capistrano/tasks/capistrano2.rb +39 -19
- data/lib/capistrano/tasks/monit.cap +60 -0
- data/lib/capistrano/tasks/sidekiq.cap +65 -21
- data/lib/capistrano/templates/sidekiq_monit.conf.erb +9 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61231f557213995443b79c4d06ceaa5de8238bd6
|
4
|
+
data.tar.gz: 489cf3778f8e5f682a45a88537411d23da415604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebbf4e4d9511849571ffc5539c7c412791dbf3bda5c66ff703a624a58ab83310e336f7c4b26e27bb96c1091eceaad8b4ec84bfdf3878c6b00e44848e5277adf2
|
7
|
+
data.tar.gz: a02c3e44e841c492a1da7ecd7adefc5b8b18b68d2d851dfd8ddab46d6d404a1aaa9fc0f9ce5a53433b31feedd5ae3315cea2adcf31c3b8513a20ab5b13eea271
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ And then execute:
|
|
22
22
|
# Capfile
|
23
23
|
|
24
24
|
require 'capistrano/sidekiq'
|
25
|
-
require 'capistrano/sidekiq/monit #to require monit tasks
|
25
|
+
require 'capistrano/sidekiq/monit' #to require monit tasks # Only for capistrano3
|
26
26
|
```
|
27
27
|
|
28
28
|
|
@@ -42,7 +42,12 @@ Configurable options, shown here with defaults:
|
|
42
42
|
:sidekiq_cmd => "#{fetch(:bundle_cmd, "bundle")} exec sidekiq" # Only for capistrano2.5
|
43
43
|
:sidekiqctl_cmd => "#{fetch(:bundle_cmd, "bundle")} exec sidekiqctl" # Only for capistrano2.5
|
44
44
|
```
|
45
|
+
## Changelog
|
46
|
+
- 0.2.0: Added sidekiq:rolling_restart - @jlecour
|
45
47
|
|
48
|
+
## Contributors
|
49
|
+
|
50
|
+
- [Jérémy Lecour] (https://github.com/jlecour)
|
46
51
|
|
47
52
|
## Contributing
|
48
53
|
|
@@ -3,13 +3,13 @@ Capistrano::Configuration.instance.load do
|
|
3
3
|
_cset(:sidekiq_default_hooks) { true }
|
4
4
|
|
5
5
|
_cset(:sidekiq_pid) { File.join(shared_path, 'pids', 'sidekiq.pid') }
|
6
|
-
_cset(:sidekiq_env) { fetch(:rack_env, fetch(:rails_env,
|
6
|
+
_cset(:sidekiq_env) { fetch(:rack_env, fetch(:rails_env, 'production')) }
|
7
7
|
_cset(:sidekiq_log) { File.join(shared_path, 'log', 'sidekiq.log') }
|
8
8
|
|
9
9
|
_cset(:sidekiq_options) { nil }
|
10
10
|
|
11
|
-
_cset(:sidekiq_cmd) { "#{fetch(:bundle_cmd,
|
12
|
-
_cset(:sidekiqctl_cmd) { "#{fetch(:bundle_cmd,
|
11
|
+
_cset(:sidekiq_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec sidekiq" }
|
12
|
+
_cset(:sidekiqctl_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec sidekiqctl" }
|
13
13
|
|
14
14
|
_cset(:sidekiq_timeout) { 10 }
|
15
15
|
_cset(:sidekiq_role) { :app }
|
@@ -34,38 +34,58 @@ Capistrano::Configuration.instance.load do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def quiet_process(pid_file, idx)
|
38
|
+
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"
|
39
|
+
end
|
40
|
+
|
41
|
+
def stop_process(pid_file, idx)
|
42
|
+
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"
|
43
|
+
end
|
44
|
+
|
45
|
+
def start_process(pid_file, idx)
|
46
|
+
args = []
|
47
|
+
args.push "--index #{idx}"
|
48
|
+
args.push "--pidfile #{pid_file}"
|
49
|
+
args.push "--environment #{fetch(:sidekiq_env)}"
|
50
|
+
args.push "--logfile #{fetch(:sidekiq_log)}" if fetch(:sidekiq_log)
|
51
|
+
args.push fetch(:sidekiq_options)
|
52
|
+
|
53
|
+
if defined?(JRUBY_VERSION)
|
54
|
+
args.push '>/dev/null 2>&1 &'
|
55
|
+
logger.info 'Since JRuby doesn\'t support Process.daemon, Sidekiq will not be running as a daemon.'
|
56
|
+
else
|
57
|
+
args.push '--daemon'
|
58
|
+
end
|
59
|
+
|
60
|
+
run "cd #{current_path} ; #{fetch(:sidekiq_cmd)} #{args.compact.join(' ')} ", :pty => false
|
61
|
+
end
|
62
|
+
|
37
63
|
desc 'Quiet sidekiq (stop accepting new work)'
|
38
64
|
task :quiet, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
39
65
|
for_each_process do |pid_file, idx|
|
40
|
-
|
66
|
+
quiet_process(pid_file, idx)
|
41
67
|
end
|
42
68
|
end
|
43
69
|
|
44
70
|
desc 'Stop sidekiq'
|
45
71
|
task :stop, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
46
72
|
for_each_process do |pid_file, idx|
|
47
|
-
|
73
|
+
stop_process(pid_file, idx)
|
48
74
|
end
|
49
75
|
end
|
50
76
|
|
51
77
|
desc 'Start sidekiq'
|
52
78
|
task :start, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
53
79
|
for_each_process do |pid_file, idx|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
args.push "--environment #{fetch(:sidekiq_env)}"
|
58
|
-
args.push "--logfile #{fetch(:sidekiq_log)}" if fetch(:sidekiq_log)
|
59
|
-
args.push fetch(:sidekiq_options)
|
60
|
-
|
61
|
-
if defined?(JRUBY_VERSION)
|
62
|
-
args.push ">/dev/null 2>&1 &"
|
63
|
-
logger.info 'Since JRuby doesn\'t support Process.daemon, Sidekiq will not be running as a daemon.'
|
64
|
-
else
|
65
|
-
args.push "--daemon"
|
66
|
-
end
|
80
|
+
start_process(pid_file, idx)
|
81
|
+
end
|
82
|
+
end
|
67
83
|
|
68
|
-
|
84
|
+
desc 'Rolling-restart sidekiq'
|
85
|
+
task :rolling_restart, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
86
|
+
for_each_process do |pid_file, idx|
|
87
|
+
stop_process(pid_file, idx)
|
88
|
+
start_process(pid_file, idx)
|
69
89
|
end
|
70
90
|
end
|
71
91
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
set :sidekiq_monit_conf_dir, -> { '/etc/monit/conf.d' }
|
4
|
+
set :monit_bin, -> { '/usr/bin/monit' }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
namespace :sidekiq do
|
10
|
+
namespace :monit do
|
11
|
+
desc 'Config Sidekiq monit-service'
|
12
|
+
task :config do
|
13
|
+
on roles(fetch(:sidekiq_role)) do |role|
|
14
|
+
@role = role
|
15
|
+
template_sidekiq 'sidekiq_monit.conf', "#{fetch(:tmp_dir)}/monit.conf", @role
|
16
|
+
sudo "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:sidekiq_monit_conf_dir)}/#{sidekiq_service_name}.conf"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Monitor Sidekiq monit-service'
|
21
|
+
task :monitor do
|
22
|
+
on roles(fetch(:sidekiq_role)) do
|
23
|
+
sudo "#{fetch(:monit_bin)} monitor #{sidekiq_service_name(index)}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Unmonitor Sidekiq monit-service'
|
28
|
+
task :unmonitor do
|
29
|
+
on roles(fetch(:sidekiq_role)) do
|
30
|
+
sudo "#{fetch(:monit_bin)} unmonitor #{sidekiq_service_name(index)}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Disable Sidekiq monit-service'
|
35
|
+
task :start do
|
36
|
+
on roles(fetch(:sidekiq_role)) do
|
37
|
+
sudo "#{fetch(:monit_bin)} start #{sidekiq_service_name(index)}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Disable Sidekiq monit-service'
|
42
|
+
task :stop do
|
43
|
+
on roles(fetch(:sidekiq_role)) do
|
44
|
+
sudo "#{fetch(:monit_bin)} stop #{sidekiq_service_name(index)}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Disable Sidekiq monit-service'
|
49
|
+
task :restart do
|
50
|
+
on roles(fetch(:sidekiq_role)) do
|
51
|
+
sudo "#{fetch(:monit_bin)} restart #{sidekiq_service_name(index)}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def sidekiq_service_name(index=nil)
|
56
|
+
fetch(:sidekiq_service_name, "sidekiq_#{fetch(:application)}") + index.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -26,7 +26,9 @@ namespace :sidekiq do
|
|
26
26
|
pids = processes_pids
|
27
27
|
pids.reverse! if reverse
|
28
28
|
pids.each_with_index do |pid_file, idx|
|
29
|
-
|
29
|
+
within current_path do
|
30
|
+
yield(pid_file, idx)
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -41,8 +43,20 @@ namespace :sidekiq do
|
|
41
43
|
pids
|
42
44
|
end
|
43
45
|
|
46
|
+
def pid_process_exists?(pid_file)
|
47
|
+
pid_file_exists?(pid_file) and test("kill -0 $( cat #{pid_file} )")
|
48
|
+
end
|
49
|
+
|
50
|
+
def pid_file_exists?(pid_file)
|
51
|
+
test("[ -f #{pid_file} ]")
|
52
|
+
end
|
53
|
+
|
44
54
|
def stop_sidekiq(pid_file)
|
45
|
-
|
55
|
+
if fetch(:stop_sidekiq_in_background, fetch(:sidekiq_run_in_background))
|
56
|
+
background :bundle, :exec, :sidekiqctl, 'stop', "#{pid_file}", fetch(:sidekiq_timeout)
|
57
|
+
else
|
58
|
+
execute :bundle, :exec, :sidekiqctl, 'stop', "#{pid_file}", fetch(:sidekiq_timeout)
|
59
|
+
end
|
46
60
|
end
|
47
61
|
|
48
62
|
def quit_sidekiq(pid_file)
|
@@ -71,7 +85,11 @@ namespace :sidekiq do
|
|
71
85
|
args.push "--daemon"
|
72
86
|
end
|
73
87
|
|
74
|
-
|
88
|
+
if fetch(:start_sidekiq_in_background, fetch(:sidekiq_run_in_background))
|
89
|
+
background :bundle, :exec, :sidekiq, args.compact.join(' ')
|
90
|
+
else
|
91
|
+
execute :bundle, :exec, :sidekiq, args.compact.join(' ')
|
92
|
+
end
|
75
93
|
end
|
76
94
|
|
77
95
|
task :add_default_hooks do
|
@@ -84,9 +102,9 @@ namespace :sidekiq do
|
|
84
102
|
desc 'Quiet sidekiq (stop processing new tasks)'
|
85
103
|
task :quiet do
|
86
104
|
on roles fetch(:sidekiq_role) do
|
87
|
-
|
88
|
-
|
89
|
-
|
105
|
+
if test("[ -d #{current_path} ]") #fixes #11
|
106
|
+
for_each_process(true) do |pid_file, idx|
|
107
|
+
if pid_process_exists?(pid_file)
|
90
108
|
quit_sidekiq(pid_file)
|
91
109
|
end
|
92
110
|
end
|
@@ -98,10 +116,8 @@ namespace :sidekiq do
|
|
98
116
|
task :stop do
|
99
117
|
on roles fetch(:sidekiq_role) do
|
100
118
|
for_each_process(true) do |pid_file, idx|
|
101
|
-
if
|
102
|
-
|
103
|
-
stop_sidekiq(pid_file)
|
104
|
-
end
|
119
|
+
if pid_process_exists?(pid_file)
|
120
|
+
stop_sidekiq(pid_file)
|
105
121
|
end
|
106
122
|
end
|
107
123
|
end
|
@@ -110,10 +126,8 @@ namespace :sidekiq do
|
|
110
126
|
desc 'Start sidekiq'
|
111
127
|
task :start do
|
112
128
|
on roles fetch(:sidekiq_role) do
|
113
|
-
|
114
|
-
|
115
|
-
start_sidekiq(pid_file)
|
116
|
-
end
|
129
|
+
for_each_process do |pid_file, idx|
|
130
|
+
start_sidekiq(pid_file, idx)
|
117
131
|
end
|
118
132
|
end
|
119
133
|
end
|
@@ -124,12 +138,24 @@ namespace :sidekiq do
|
|
124
138
|
invoke 'sidekiq:start'
|
125
139
|
end
|
126
140
|
|
141
|
+
desc 'Rolling-restart sidekiq'
|
142
|
+
task :rolling_restart do
|
143
|
+
on roles fetch(:sidekiq_role) do
|
144
|
+
for_each_process(true) do |pid_file, idx|
|
145
|
+
if pid_process_exists?(pid_file)
|
146
|
+
stop_sidekiq(pid_file)
|
147
|
+
end
|
148
|
+
start_sidekiq(pid_file, idx)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
127
153
|
#delete any pid file not in use
|
128
154
|
task :cleanup do
|
129
155
|
on roles fetch(:sidekiq_role) do
|
130
156
|
for_each_process do |pid_file, idx|
|
131
|
-
if
|
132
|
-
execute "rm #{pid_file}" unless
|
157
|
+
if pid_file_exists?(pid_file)
|
158
|
+
execute "rm #{pid_file}" unless pid_process_exists?(pid_file)
|
133
159
|
end
|
134
160
|
end
|
135
161
|
end
|
@@ -140,14 +166,32 @@ namespace :sidekiq do
|
|
140
166
|
task :respawn do
|
141
167
|
invoke 'sidekiq:cleanup'
|
142
168
|
on roles fetch(:sidekiq_role) do
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
start_sidekiq(pid_file, idx)
|
147
|
-
end
|
169
|
+
for_each_process do |pid_file, idx|
|
170
|
+
unless pid_file_exists?(pid_file)
|
171
|
+
start_sidekiq(pid_file, idx)
|
148
172
|
end
|
149
173
|
end
|
150
174
|
end
|
151
175
|
end
|
152
176
|
|
177
|
+
|
178
|
+
def template_sidekiq(from, to, role)
|
179
|
+
[
|
180
|
+
File.join('lib','capistrano','templates',"#{from}-#{role.hostname}-#{fetch(:stage)}.rb"),
|
181
|
+
File.join('lib','capistrano','templates',"#{from}-#{role.hostname}.rb"),
|
182
|
+
File.join('lib','capistrano','templates',"#{from}-#{fetch(:stage)}.rb"),
|
183
|
+
File.join('lib','capistrano','templates',"#{from}.rb.erb"),
|
184
|
+
File.join('lib','capistrano','templates',"#{from}.rb"),
|
185
|
+
File.join('lib','capistrano','templates',"#{from}.erb"),
|
186
|
+
File.expand_path("../../templates/#{from}.rb.erb", __FILE__),
|
187
|
+
File.expand_path("../../templates/#{from}.erb", __FILE__)
|
188
|
+
].each do |path|
|
189
|
+
if File.file?(path)
|
190
|
+
erb = File.read(path)
|
191
|
+
upload! StringIO.new(ERB.new(erb).result(binding)), to
|
192
|
+
break
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
153
197
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Monit configuration for Sidekiq : <%= fetch(:application) %>
|
2
|
+
<% processes_pids.each_with_index do |pid_file, idx| %>
|
3
|
+
check process <%= sidekiq_service_name(idx) %>
|
4
|
+
with pidfile "<%= pid_file %>"
|
5
|
+
start program = "/usr/bin/sudo -u <%= @role.user %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec sidekiq -P <%= pid_file %>'" with timeout 30 seconds
|
6
|
+
stop program = "/usr/bin/sudo -u <%= @role.user %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec sidekiqctl stop <%= pid_file %>'" with timeout <%= fetch(:sidekiq_timeout).to_i + 10 %> seconds
|
7
|
+
group <%= fetch(:sidekiq_monit_group, fetch(:application)) %>-sidekiq
|
8
|
+
|
9
|
+
<% 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.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdelkader Boudih
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
@@ -53,9 +53,12 @@ files:
|
|
53
53
|
- capistrano-sidekiq.gemspec
|
54
54
|
- lib/capistrano-sidekiq.rb
|
55
55
|
- lib/capistrano/sidekiq.rb
|
56
|
+
- lib/capistrano/sidekiq/monit.rb
|
56
57
|
- lib/capistrano/sidekiq/version.rb
|
57
58
|
- lib/capistrano/tasks/capistrano2.rb
|
59
|
+
- lib/capistrano/tasks/monit.cap
|
58
60
|
- lib/capistrano/tasks/sidekiq.cap
|
61
|
+
- lib/capistrano/templates/sidekiq_monit.conf.erb
|
59
62
|
homepage: https://github.com/seuros/capistrano-sidekiq
|
60
63
|
licenses:
|
61
64
|
- LGPL-3.0
|