mina-sidekiq 1.0.3 → 1.1.0

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
- SHA1:
3
- metadata.gz: e83a12846c227f7fb2556d7f7b790b2fe202a50a
4
- data.tar.gz: 4dbb611c7f3d9f859d2dfdff30520059e52c17f8
2
+ SHA256:
3
+ metadata.gz: b6b58dc398da8db743c4f5f063cf60cabc54e546463c8ca9504afed5855ee4a5
4
+ data.tar.gz: 46cd45d6d4ef1ab10a93892baf0fab90d7899b4520e2afd1a068e0fb90ab7dae
5
5
  SHA512:
6
- metadata.gz: 8599964fe653f428528e1932b63b4409f0470e1c795f6bc9b3e4238a92b1be8e41907c7015a258b8aca032116f287488f8bafab631e56a2ca03b896a2e867cd3
7
- data.tar.gz: 2e64560593ce53ad5bcb9e7c05b928d1d67a6cb0bd96d71c03972094c101e01102169695a2662a5e7528dda96144c3b97740499c8cc54d39281e9ec81345d260
6
+ metadata.gz: d8902d7d2b9f28020b5049dcaf661fbf7ab07b644b9e4da7a5b737a628acbd38de5480386bd281430a9fbc7d3c7c28f7e4d63a48cd10030805b89af9bd18feee
7
+ data.tar.gz: dbff1c1aea66bb4a111e29fc3c9f5c368d22819b0e7e9329d558f99cefa9ce4bc199bc2bd8035ccd1b7b23b68f7a9fc7df5e1c9a3e2b5fd69b0f8aedf43a9f79
@@ -1,6 +1,11 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 1.1.0 2020-07-18
5
+ ----------------
6
+ * Add sidekiq 6 support, including support for unprivileged deployments
7
+ * Allow multiple sidekiq process with different configs
8
+
4
9
  1.0.3 2017-11-05
5
10
  ----------------
6
11
  * replace deprecated dependency on environment task with remote_environment
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  mina-sidekiq
2
2
  ============
3
3
 
4
- [![Build Status](https://travis-ci.org/Mic92/mina-sidekiq.png?branch=master)](https://travis-ci.org/Mic92/mina-sidekiq)
5
-
6
4
  mina-sidekiq is a gem that adds tasks to aid in the deployment of [Sidekiq](http://mperham.github.com/sidekiq/)
7
5
  using [Mina](http://nadarei.co/mina).
8
6
 
9
7
  Starting with 1.0.0 this gem requires Mina 1.0! (thanks [@devvmh](https://github.com/devvmh))
10
8
 
9
+ Support sidekiq > 6.0, reference project capistrano-sidekiq, github: https://github.com/seuros/capistrano-sidekiq
10
+
11
11
  # Getting Start
12
12
 
13
13
  ## Installation
@@ -43,6 +43,71 @@ task :deploy do
43
43
  end
44
44
  end
45
45
  ```
46
+ ## Support sidekiq > 6.0
47
+
48
+ Set init system to systemd in the mina deploy config:
49
+
50
+ ```ruby
51
+ set :init_system, :systemd
52
+ ```
53
+
54
+ Enable lingering for systemd user account
55
+
56
+ ```
57
+ loginctl enable-linger USERACCOUNT
58
+ ```
59
+
60
+ Install systemd.service template file and enable the service with:
61
+
62
+ ```
63
+ bundle exec mina sidekiq:install
64
+ ```
65
+
66
+ Default name for the service file is sidekiq-env.service. This can be changed as needed, for example:
67
+
68
+ ```ruby
69
+ set :service_unit_name, "sidekiq-#{fetch(:rails_env)}.service"
70
+ ```
71
+
72
+ Default systemctl command is ```systemctl --user```, this can be changed, for example:
73
+
74
+ ```ruby
75
+ set :systemctl_command, 'systemctl --user'
76
+ ```
77
+ For non privileged user (non sudo) usage set up path for systemctl unit file:
78
+
79
+ ```ruby
80
+ set :service_unit_path, '/home/www/.config/systemd/user'
81
+ ```
82
+
83
+ where ```www``` is the username. For details see systemctl [doc page](https://www.freedesktop.org/software/systemd/man/systemd.unit.html)
84
+
85
+ To use systemctl integration with rbenv bundler path must be setted:
86
+
87
+ ```ruby
88
+ set :bundler_path, '/home/www/.rbenv/shims/bundler'
89
+ ```
90
+
91
+ To get bundler path use:
92
+
93
+ ```bash
94
+ which bundler
95
+ ```
96
+
97
+
98
+ ## Integration with upstart
99
+
100
+ Set init system to upstart in the cap deploy config:
101
+
102
+ ```ruby
103
+ set :init_system, :upstart
104
+ ```
105
+
106
+ Set upstart service name:
107
+
108
+ ```ruby
109
+ set :upstart_service_name, 'sidekiq'
110
+ ```
46
111
 
47
112
 
48
113
  ## Available Tasks
@@ -53,16 +118,22 @@ end
53
118
  * sidekiq:quiet
54
119
  * sidekiq:log
55
120
 
121
+ sidekiq > 6.0
122
+ * sidekiq:install
123
+ * sidekiq:uninstall
124
+
56
125
  ## Available Options
57
126
 
58
- | Option | Description |
59
- | ------------------- | ------------------------------------------------------------------------------ |
60
- | *sidekiq* | Sets the path to sidekiq. |
61
- | *sidekiqctl* | Sets the path to sidekiqctl. |
62
- | *sidekiq\_timeout* | Sets a upper limit of time a worker is allowed to finish, before it is killed. |
63
- | *sidekiq\_log* | Sets the path to the log file of sidekiq. |
64
- | *sidekiq\_pid* | Sets the path to the pid file of a sidekiq worker. |
65
- | *sidekiq_processes* | Sets the number of sidekiq processes launched. |
127
+ | Option | Description |
128
+ | ------------------- | ------------------------------------------------------------------------------------------------- |
129
+ | *sidekiq* | Sets the path to sidekiq. |
130
+ | *sidekiqctl* | Sets the path to sidekiqctl. |
131
+ | *sidekiq\_timeout* | Sets a upper limit of time a worker is allowed to finish, before it is killed. |
132
+ | *sidekiq\_log* | Sets the path to the log file of sidekiq. |
133
+ | *sidekiq\_pid* | Sets the path to the pid file of a sidekiq worker. |
134
+ | *sidekiq_processes* | Sets the number of sidekiq processes launched. |
135
+ | *sidekiq_config* | Sets the config file path. |
136
+ | *sidekiq_configs* | Sets the config file paths when using more than one sidekiq process with different configuration. |
66
137
 
67
138
  ## Testing
68
139
 
@@ -33,16 +33,26 @@ set :sidekiq, -> { "#{fetch(:bundle_bin)} exec sidekiq" }
33
33
 
34
34
  # ### sidekiqctl
35
35
  # Sets the path to sidekiqctl.
36
- set :sidekiqctl, -> { "#{fetch(:bundle_prefix)} sidekiqctl" }
36
+ set :sidekiqctl, -> { "#{fetch(:bundle_bin)} exec sidekiqctl" }
37
37
 
38
38
  # ### sidekiq_timeout
39
39
  # Sets a upper limit of time a process is allowed to finish, before it is killed by sidekiqctl.
40
40
  set :sidekiq_timeout, 11
41
41
 
42
42
  # ### sidekiq_config
43
- # Sets the path to the configuration file of sidekiq
43
+ # Sets the path to the configuration file of sidekiq.
44
44
  set :sidekiq_config, -> { "#{fetch(:current_path)}/config/sidekiq.yml" }
45
45
 
46
+ # ### sidekiq_configs
47
+ # A list of configuration file paths. Each file path will be assigned to one sidekiq
48
+ # instance in order. When specified sidekiq_config will be ignored.
49
+ set :sidekiq_configs, -> {
50
+ [
51
+ # "#{fetch(:current_path)}/config/sidekiq_1.yml",
52
+ # "#{fetch(:current_path)}/config/sidekiq_2.yml"
53
+ ]
54
+ }
55
+
46
56
  # ### sidekiq_log
47
57
  # Sets the path to the log file of sidekiq
48
58
  #
@@ -61,6 +71,16 @@ set :sidekiq_processes, 1
61
71
  # Sets the number of sidekiq threads per process (overrides value in sidekiq.yml)
62
72
  set :sidekiq_concurrency, nil
63
73
 
74
+ set :sidekiq_user, nil
75
+
76
+ # Init system integration
77
+ set :init_system, -> { nil }
78
+ # systemd integration
79
+ set :service_unit_name, "sidekiq-#{fetch(:rails_env)}.service"
80
+ set :systemctl_command, 'systemctl --user'
81
+
82
+ set :upstart_service_name, "sidekiq"
83
+
64
84
  # ## Control Tasks
65
85
  namespace :sidekiq do
66
86
  def for_each_process(&block)
@@ -78,15 +98,22 @@ namespace :sidekiq do
78
98
  desc "Quiet sidekiq (stop accepting new work)"
79
99
  task :quiet => :remote_environment do
80
100
  comment 'Quiet sidekiq (stop accepting new work)'
81
- in_path(fetch(:current_path)) do
82
- for_each_process do |pid_file, idx|
83
- command %{
84
- if [ -f #{pid_file} ] && kill -0 `cat #{pid_file}` > /dev/null 2>&1; then
85
- #{fetch(:sidekiqctl)} quiet #{pid_file}
86
- else
87
- echo 'Skip quiet command (no pid file found)'
88
- fi
89
- }.strip
101
+ case fetch(:init_system)
102
+ when :systemd
103
+ command %{ #{ fetch(:systemctl_command) } reload #{ fetch(:service_unit_name) } }
104
+ when :upstart
105
+ command %{ sudo service #{ fetch(:upstart_service_name) } reload }
106
+ else
107
+ in_path(fetch(:current_path)) do
108
+ for_each_process do |pid_file, idx|
109
+ command %{
110
+ if [ -f #{pid_file} ] && kill -0 `cat #{pid_file}` > /dev/null 2>&1; then
111
+ #{fetch(:sidekiqctl)} quiet #{pid_file}
112
+ else
113
+ echo 'Skip quiet command (no pid file found)'
114
+ fi
115
+ }.strip
116
+ end
90
117
  end
91
118
  end
92
119
  end
@@ -95,15 +122,22 @@ namespace :sidekiq do
95
122
  desc "Stop sidekiq"
96
123
  task :stop => :remote_environment do
97
124
  comment 'Stop sidekiq'
98
- in_path(fetch(:current_path)) do
99
- for_each_process do |pid_file, idx|
100
- command %{
101
- if [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then
102
- #{fetch(:sidekiqctl)} stop #{pid_file} #{fetch(:sidekiq_timeout)}
103
- else
104
- echo 'Skip stopping sidekiq (no pid file found)'
105
- fi
106
- }.strip
125
+ case fetch(:init_system)
126
+ when :systemd
127
+ command %{ #{ fetch(:systemctl_command) } stop #{ fetch(:service_unit_name) } }
128
+ when :upstart
129
+ command %{ sudo service #{ fetch(:upstart_service_name) } stop }
130
+ else
131
+ in_path(fetch(:current_path)) do
132
+ for_each_process do |pid_file, idx|
133
+ command %{
134
+ if [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then
135
+ #{fetch(:sidekiqctl)} stop #{pid_file} #{fetch(:sidekiq_timeout)}
136
+ else
137
+ echo 'Skip stopping sidekiq (no pid file found)'
138
+ fi
139
+ }.strip
140
+ end
107
141
  end
108
142
  end
109
143
  end
@@ -112,19 +146,85 @@ namespace :sidekiq do
112
146
  desc "Start sidekiq"
113
147
  task :start => :remote_environment do
114
148
  comment 'Start sidekiq'
115
- in_path(fetch(:current_path)) do
116
- for_each_process do |pid_file, idx|
117
- sidekiq_concurrency = fetch(:sidekiq_concurrency)
118
- concurrency_arg = if sidekiq_concurrency.nil?
119
- ""
120
- else
121
- "-c #{sidekiq_concurrency}"
122
- end
123
- command %[#{fetch(:sidekiq)} -d -e #{fetch(:rails_env)} #{concurrency_arg} -C #{fetch(:sidekiq_config)} -i #{idx} -P #{pid_file} -L #{fetch(:sidekiq_log)}]
149
+ case fetch(:init_system)
150
+ when :systemd
151
+ command %{ #{ fetch(:systemctl_command) } start #{ fetch(:service_unit_name) } }
152
+ when :upstart
153
+ command %{ sudo service #{ fetch(:upstart_service_name) } start }
154
+ else
155
+ in_path(fetch(:current_path)) do
156
+ for_each_process do |pid_file, idx|
157
+ sidekiq_config = fetch(:sidekiq_configs)[idx] || fetch(:sidekiq_config)
158
+ sidekiq_concurrency = fetch(:sidekiq_concurrency)
159
+ concurrency_arg = if sidekiq_concurrency.nil?
160
+ ""
161
+ else
162
+ "-c #{sidekiq_concurrency}"
163
+ end
164
+ command_line = %[#{fetch(:sidekiq)} -d -e #{fetch(:rails_env)} #{concurrency_arg} -C #{sidekiq_config} -i #{idx} -P #{pid_file}]
165
+ command_line += " -L #{fetch(:sidekiq_log)}" if fetch(:sidekiq_log)
166
+
167
+ command command_line
168
+ end
124
169
  end
125
170
  end
126
171
  end
127
172
 
173
+ task :install do
174
+ case fetch(:init_system)
175
+ when :systemd
176
+ create_systemd_template
177
+ end
178
+ end
179
+
180
+ task :uninstall do
181
+ case fetch(:init_system)
182
+ when :systemd
183
+ command %{ #{ fetch(:systemctl_command) } disable #{fetch(:service_unit_name)} }
184
+ command %{ rm #{File.join(fetch(:service_unit_path, fetch_systemd_unit_path),fetch(:service_unit_name))} }
185
+ end
186
+ end
187
+
188
+ def create_systemd_template
189
+ template = %{
190
+ [Unit]
191
+ Description=sidekiq for #{fetch(:application)} #{fetch(:app_name)}
192
+ After=syslog.target network.target
193
+
194
+ [Service]
195
+ Type=simple
196
+ Environment=RAILS_ENV=#{ fetch(:rails_env) }
197
+ StandardOutput=append:#{fetch(:deploy_to)}/current/log/sidekiq.log
198
+ StandardError=append:#{fetch(:deploy_to)}/current/log/sidekiq.log
199
+ WorkingDirectory=#{fetch(:deploy_to)}/current
200
+ ExecStart=#{fetch(:bundler_path, '/usr/local/bin/bundler')} exec sidekiq -e #{fetch(:rails_env)}
201
+ ExecReload=/bin/kill -TSTP $MAINPID
202
+ ExecStop=/bin/kill -TERM $MAINPID
203
+ RestartSec=1
204
+ Restart=on-failure
205
+
206
+ SyslogIdentifier=sidekiq
207
+
208
+ [Install]
209
+ WantedBy=default.target
210
+ }
211
+ systemd_path = fetch(:service_unit_path, fetch_systemd_unit_path)
212
+ service_path = systemd_path + "/" + fetch(:service_unit_name)
213
+ comment %{Creating systemctl unit file}
214
+ command %{ mkdir -p #{systemd_path} }
215
+ command %{ touch #{service_path} }
216
+ command %{ echo "#{ template }" > #{ service_path } }
217
+ comment %{Reloading systemctl daemon}
218
+ command %{ #{ fetch(:systemctl_command) } daemon-reload }
219
+ comment %{Enabling sidekiq service}
220
+ command %{ #{ fetch(:systemctl_command) } enable #{ service_path } }
221
+ end
222
+
223
+ def fetch_systemd_unit_path
224
+ home_dir = '/usr'
225
+ File.join(home_dir, "lib", "systemd", "user")
226
+ end
227
+
128
228
  # ### sidekiq:restart
129
229
  desc "Restart sidekiq"
130
230
  task :restart do
@@ -136,4 +236,5 @@ namespace :sidekiq do
136
236
  task :log => :remote_environment do
137
237
  command %[tail -f #{fetch(:sidekiq_log)}]
138
238
  end
239
+
139
240
  end
@@ -1,5 +1,5 @@
1
1
  module MinaSidekiq
2
2
  def self.version
3
- '1.0.3'
3
+ '1.1.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joerg Thalheim
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-05 00:00:00.000000000 Z
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mina
@@ -77,7 +77,7 @@ homepage: http://github.com/Mic92/mina-sidekiq
77
77
  licenses:
78
78
  - MIT
79
79
  metadata: {}
80
- post_install_message:
80
+ post_install_message:
81
81
  rdoc_options: []
82
82
  require_paths:
83
83
  - lib
@@ -92,9 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.6.13
97
- signing_key:
95
+ rubygems_version: 3.1.3
96
+ signing_key:
98
97
  specification_version: 4
99
98
  summary: Tasks to deploy Sidekiq with mina.
100
99
  test_files: