capistrano-sidekiq 2.2.0 → 2.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f55ede23a48a3ff9319774a09692f01137ae02ef54b6f27bead18518650973c
4
- data.tar.gz: 3587deeffde5524d5390e0fc60e474c0bf1c34c048422a15a30efc8cb5460ca2
3
+ metadata.gz: f1305b19a72ddd0258d9802bb785bf4b35b8a365341ace29cc7f13a73b48e275
4
+ data.tar.gz: fb3d6649a6d38017d246b029b724054d19ab1121a5290cfc059435c49d71f1b8
5
5
  SHA512:
6
- metadata.gz: 46b1223d92a931beed504100ed25debb4c1b5d0a98a0e60b279c0d283ac5356a5ed5c3d80b87dbe8220cc8faa60999ab3d1266147ff22d1968b8545e313a1f00
7
- data.tar.gz: da0d5e2e30b0fefc4a1e37beae281bbbba52417fa4446f13bcff69bb395df9250945797f76a039ae5774574d24ca7b2d563c2f4013fa8726faaa00b3d66c857a
6
+ metadata.gz: f785e552f7e6d5ae48239cad1190450d153340bcbeb4b00128a5ef26f809561b0cd638e759221f9dfda2916812a60071ca597ab54a58b7973894777df2465baf
7
+ data.tar.gz: b59f3805ca7517b3b7378f05dd924c9135eb5cca57475b2b538d50ed0c379be383a2ec4cc8bf666e3d72cbb846df5fd5ace2d8f4262aeffc722b7082c2613760
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.1.2
1
+ ruby 2.7.6
data/CHANGELOG.md CHANGED
@@ -1,8 +1,18 @@
1
1
  # Changelog
2
2
 
3
- ## [2.2.0](https://github.com/seuros/capistrano-sidekiq/tree/2.2.0) (2022-05-16)
3
+ ## [2.3.0](https://github.com/seuros/capistrano-sidekiq/tree/2.3.0) (2022-05-17)
4
4
 
5
- [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.1.0...2.2.0)
5
+ [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.2.0...2.3.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - fix sidekiq processes naming when count is 1 [\#300](https://github.com/seuros/capistrano-sidekiq/pull/300) ([seuros](https://github.com/seuros))
10
+ - Support multiple processes in `sidekiq:install` [\#299](https://github.com/seuros/capistrano-sidekiq/pull/299) ([lloydwatkin](https://github.com/lloydwatkin))
11
+ - fix: monit config template [\#288](https://github.com/seuros/capistrano-sidekiq/pull/288) ([jpickwell](https://github.com/jpickwell))
12
+
13
+ ## [v2.2.0](https://github.com/seuros/capistrano-sidekiq/tree/v2.2.0) (2022-05-16)
14
+
15
+ [Full Changelog](https://github.com/seuros/capistrano-sidekiq/compare/v2.1.0...v2.2.0)
6
16
 
7
17
  **Merged pull requests:**
8
18
 
@@ -270,3 +280,7 @@
270
280
  - More robust version checking [\#4](https://github.com/seuros/capistrano-sidekiq/pull/4) ([jlecour](https://github.com/jlecour))
271
281
  - More explicit start command [\#3](https://github.com/seuros/capistrano-sidekiq/pull/3) ([jlecour](https://github.com/jlecour))
272
282
  - Improve pid and log files settings [\#1](https://github.com/seuros/capistrano-sidekiq/pull/1) ([jlecour](https://github.com/jlecour))
283
+
284
+
285
+
286
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ gemspec
5
5
 
6
6
  gem "bump", "~> 0.10.0"
7
7
 
8
- gem "github_changelog_generator", "~> 1.16"
8
+ gem "github_changelog_generator", "~> 1.16"
data/README.md CHANGED
@@ -22,8 +22,6 @@ And then execute:
22
22
  # Then select your service manager
23
23
  install_plugin Capistrano::Sidekiq::Systemd
24
24
  # or
25
- install_plugin Capistrano::Sidekiq::Upstart # tests needed
26
- # or
27
25
  install_plugin Capistrano::Sidekiq::Monit # tests needed
28
26
  ```
29
27
 
@@ -67,13 +65,6 @@ Configurable options - Please ensure you check your version's branch for the ava
67
65
  ```
68
66
  See `capistrano/sidekiq/helpers.rb` for other undocumented configuration settings.
69
67
 
70
- ## Known issues with Capistrano 3
71
-
72
- There is a known bug that prevents sidekiq from starting when pty is true on Capistrano 3.
73
- ```ruby
74
- set :pty, false
75
- ```
76
-
77
68
  ## Bundler
78
69
 
79
70
  If you'd like to prepend `bundle exec` to your sidekiq and sidekiqctl calls, modify the SSHKit command maps
data/Rakefile CHANGED
@@ -5,5 +5,5 @@ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
5
5
  config.user = 'seuros'
6
6
  config.project = 'capistrano-sidekiq'
7
7
  config.issues = false
8
- config.future_release = '2.2.0'
8
+ config.future_release = '2.3.0'
9
9
  end
@@ -1,22 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Capistrano
2
4
  module Sidekiq::Helpers
3
5
 
4
6
  def sidekiq_require
5
- if fetch(:sidekiq_require)
6
- "--require #{fetch(:sidekiq_require)}"
7
- end
7
+ "--require #{fetch(:sidekiq_require)}" if fetch(:sidekiq_require)
8
8
  end
9
9
 
10
10
  def sidekiq_config
11
- if fetch(:sidekiq_config)
12
- "--config #{fetch(:sidekiq_config)}"
13
- end
11
+ "--config #{fetch(:sidekiq_config)}" if fetch(:sidekiq_config)
14
12
  end
15
13
 
16
14
  def sidekiq_concurrency
17
- if fetch(:sidekiq_concurrency)
18
- "--concurrency #{fetch(:sidekiq_concurrency)}"
19
- end
15
+ "--concurrency #{fetch(:sidekiq_concurrency)}" if fetch(:sidekiq_concurrency)
20
16
  end
21
17
 
22
18
  def sidekiq_queues
@@ -29,14 +25,12 @@ module Capistrano
29
25
  fetch(:sidekiq_log)
30
26
  end
31
27
 
32
- def switch_user(role)
28
+ def switch_user(role, &block)
33
29
  su_user = sidekiq_user(role)
34
30
  if su_user == role.user
35
31
  yield
36
32
  else
37
- as su_user do
38
- yield
39
- end
33
+ as su_user, &block
40
34
  end
41
35
  end
42
36
 
@@ -55,6 +49,5 @@ module Capistrano
55
49
  def expanded_bundle_path
56
50
  backend.capture(:echo, SSHKit.config.command_map[:bundle]).strip
57
51
  end
58
-
59
52
  end
60
53
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Capistrano
2
4
  class Sidekiq::Monit < Capistrano::Plugin
3
5
  include Sidekiq::Helpers
@@ -13,7 +15,7 @@ module Capistrano
13
15
  end
14
16
 
15
17
  def define_tasks
16
- eval_rakefile File.expand_path('../../tasks/monit.rake', __FILE__)
18
+ eval_rakefile File.expand_path('../tasks/monit.rake', __dir__)
17
19
  end
18
20
  end
19
21
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Capistrano
2
4
  class Sidekiq::Systemd < Capistrano::Plugin
3
5
  include Sidekiq::Helpers
4
6
 
5
7
  def set_defaults
6
- set_if_empty :sidekiq_service_unit_name, 'sidekiq' # This will change in version 3.0.0 to {application}-sidekiq
8
+ set_if_empty :sidekiq_service_unit_name, 'sidekiq' # This will change in version 3.0.0 to {application}_sidekiq_{stage}
7
9
  set_if_empty :sidekiq_service_unit_user, :user # :system
8
10
  set_if_empty :sidekiq_enable_lingering, true
9
11
  set_if_empty :sidekiq_lingering_user, nil
@@ -11,7 +13,7 @@ module Capistrano
11
13
  end
12
14
 
13
15
  def define_tasks
14
- eval_rakefile File.expand_path('../../tasks/systemd.rake', __FILE__)
16
+ eval_rakefile File.expand_path('../tasks/systemd.rake', __dir__)
15
17
  end
16
18
  end
17
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Capistrano
2
- SidekiqVERSION = '2.2.0'
4
+ SidekiqVERSION = '2.3.0'
3
5
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'capistrano/bundler'
2
- require "capistrano/plugin"
4
+ require 'capistrano/plugin'
3
5
 
4
6
  module Capistrano
5
7
  class Sidekiq < Capistrano::Plugin
6
8
  def define_tasks
7
- eval_rakefile File.expand_path('../tasks/sidekiq.rake', __FILE__)
9
+ eval_rakefile File.expand_path('tasks/sidekiq.rake', __dir__)
8
10
  end
9
11
 
10
12
  def set_defaults
@@ -21,11 +23,9 @@ module Capistrano
21
23
  # Bundler integration
22
24
  append :bundle_bins, 'sidekiq', 'sidekiqctl'
23
25
  end
24
-
25
26
  end
26
27
  end
27
28
 
28
29
  require_relative 'sidekiq/helpers'
29
30
  require_relative 'sidekiq/systemd'
30
- require_relative 'sidekiq/upstart'
31
31
  require_relative 'sidekiq/monit'
@@ -146,18 +146,25 @@ namespace :sidekiq do
146
146
  def create_systemd_template
147
147
  ctemplate = compiled_template
148
148
  systemd_path = fetch(:service_unit_path, fetch_systemd_unit_path)
149
- systemd_file_name = File.join(systemd_path, sidekiq_service_file_name)
150
-
151
149
  backend.execute :mkdir, '-p', systemd_path if fetch(:sidekiq_service_unit_user) == :user
152
150
 
153
- temp_file_name = File.join('/tmp', sidekiq_service_file_name)
154
- backend.upload!(StringIO.new(ctemplate), temp_file_name)
155
- if fetch(:sidekiq_service_unit_user) == :system
156
- backend.execute :sudo, :mv, temp_file_name, systemd_file_name
157
- backend.execute :sudo, :systemctl, 'daemon-reload'
151
+ if sidekiq_processes > 1
152
+ range = 1..sidekiq_processes
158
153
  else
159
- backend.execute :mv, temp_file_name, systemd_file_name
160
- backend.execute :systemctl, '--user', 'daemon-reload'
154
+ range = 0..0
155
+ end
156
+ range.each do |index|
157
+ temp_file_name = File.join('/tmp', sidekiq_service_file_name(index))
158
+ systemd_file_name = File.join(systemd_path, sidekiq_service_file_name(index))
159
+ backend.upload!(StringIO.new(ctemplate), temp_file_name)
160
+
161
+ if fetch(:sidekiq_service_unit_user) == :system
162
+ backend.execute :sudo, :mv, temp_file_name, systemd_file_name
163
+ backend.execute :sudo, :systemctl, 'daemon-reload'
164
+ else
165
+ backend.execute :mv, temp_file_name, systemd_file_name
166
+ backend.execute :systemctl, '--user', 'daemon-reload'
167
+ end
161
168
  end
162
169
  end
163
170
 
@@ -200,8 +207,7 @@ namespace :sidekiq do
200
207
  else
201
208
  [:systemctl, '--user']
202
209
  end
203
-
204
- if process
210
+ if process && sidekiq_processes > 1
205
211
  execute_array.push(
206
212
  *args, sidekiq_service_unit_name(process: process)
207
213
  ).flatten
@@ -255,15 +261,14 @@ namespace :sidekiq do
255
261
  end.join(' ')
256
262
  end
257
263
 
258
- def sidekiq_service_file_name
259
- "#{fetch(:sidekiq_service_unit_name)}.service"
264
+ def sidekiq_service_file_name(index = nil)
265
+ return "#{fetch(:sidekiq_service_unit_name)}.service" if index.to_i.zero?
266
+ "#{fetch(:sidekiq_service_unit_name)}@#{index}.service"
260
267
  end
261
268
 
262
269
  def sidekiq_service_unit_name(process: nil)
263
- if process
270
+ if process && sidekiq_processes > 1
264
271
  "#{fetch(:sidekiq_service_unit_name)}@#{process}"
265
- elsif sidekiq_processes > 1
266
- "#{fetch(:sidekiq_service_unit_name)}@{1..#{sidekiq_processes}}"
267
272
  else
268
273
  fetch(:sidekiq_service_unit_name)
269
274
  end
@@ -272,9 +277,7 @@ namespace :sidekiq do
272
277
  # process = 1 | sidekiq_systemd_1.yaml
273
278
  # process = nil | sidekiq_systemd_%i.yaml
274
279
  def sidekiq_systemd_config_name(process = nil)
275
- file_name = 'sidekiq_systemd_'
276
- file_name << (process&.to_s || '%i')
277
- "#{file_name}.yaml"
280
+ "sidekiq_systemd_#{(process&.to_s || '%i')}.yaml"
278
281
  end
279
282
 
280
283
  def config_per_process?
@@ -1,6 +1,8 @@
1
- # Monit configuration for Sidekiq : <%= fetch(:application) %>
2
- check process <%= sidekiq_service_name %>
3
- matching 'sidekiq .* <%= fetch(:full_app_name) %>'
4
- start program = "/bin/su - <%= sidekiq_user(role) %> -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec sidekiq -e <%= fetch(:sidekiq_env) %> <%= sidekiq_config %> <%= sidekiq_concurrency %> <%= sidekiq_require %> <%= sidekiq_queues %> <%= sidekiq_logfile ? ">> #{sidekiq_logfile} 2>&1" : nil %> &'" with timeout 30 seconds
5
- stop program = "/bin/su - <%= sidekiq_user(role) %> -c 'ps -ax | grep "<%= "sidekiq .* #{fetch(:full_app_name)}" %>" | grep -v grep | awk "{print \$1}" | xargs --no-run-if-empty kill'" with timeout <%= fetch(:sidekiq_timeout).to_i + 10 %> seconds
1
+ # Monit configuration for Sidekiq
2
+ # Service name: <%= sidekiq_service_name %>
3
+ #
4
+ check process <%= sidekiq_service_name %>
5
+ matching 'sidekiq .* <%= fetch(:application) %>'
6
+ start program = "/bin/su - <%= sidekiq_user(role) %> -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec sidekiq -e <%= fetch(:sidekiq_env) %> <%= sidekiq_config %> <%= sidekiq_concurrency %> <%= sidekiq_require %> <%= sidekiq_queues %> <%= sidekiq_logfile ? ">> #{sidekiq_logfile} 2>&1" : nil %> &'" with timeout <%= fetch(:sidekiq_timeout).to_i + 10 %> seconds
7
+ stop program = "/bin/su - <%= sidekiq_user(role) %> -c 'ps ax | grep "<%= "sidekiq .* #{fetch(:application)}" %>" | grep -v grep | awk "{print \$1}" | xargs --no-run-if-empty kill'" with timeout <%= fetch(:sidekiq_timeout).to_i + 10 %> seconds
6
8
  group <%= fetch(:sidekiq_monit_group) || fetch(:application) %>-sidekiq
@@ -5,13 +5,13 @@
5
5
  # Customize this file based on your bundler location, app directory, etc.
6
6
  # Customize and copy this into /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu).
7
7
  # Then run:
8
- # - systemctl enable sidekiq
9
- # - systemctl {start,stop,restart} sidekiq
8
+ # - systemctl enable <%= sidekiq_service_unit_name %>
9
+ # - systemctl {start,stop,restart} <%= sidekiq_service_unit_name %>
10
10
  #
11
11
  # This file corresponds to a single Sidekiq process. Add multiple copies
12
12
  # to run multiple processes (sidekiq-1, sidekiq-2, etc).
13
13
  #
14
- # Use `journalctl -u sidekiq -rn 100` to view the last 100 lines of log output.
14
+ # Use `journalctl -u <%= sidekiq_service_unit_name %> -rn 100` to view the last 100 lines of log output.
15
15
  #
16
16
  [Unit]
17
17
  Description=sidekiq for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>
@@ -44,8 +44,7 @@ WatchdogSec=10
44
44
  WorkingDirectory=<%= File.join(fetch(:deploy_to), 'current') %>
45
45
  ExecStart=<%= expanded_bundle_path %> exec sidekiq -e <%= fetch(:sidekiq_env) %> <%= sidekiq_config %> <%= sidekiq_concurrency %> <%= sidekiq_queues %>
46
46
 
47
- # Use `systemctl kill -s TSTP sidekiq` to quiet the Sidekiq process
48
-
47
+ # Use `systemctl kill -s TSTP <%= sidekiq_service_unit_name %>` to quiet the Sidekiq process
49
48
  <%="User=#{sidekiq_user}" if sidekiq_user %>
50
49
  UMask=0002
51
50
 
@@ -63,8 +62,7 @@ Restart=on-failure
63
62
  <%="StandardOutput=append:#{fetch(:sidekiq_log)}" if fetch(:sidekiq_log) %>
64
63
  <%="StandardError=append:#{fetch(:sidekiq_error_log)}" if fetch(:sidekiq_error_log) %>
65
64
 
66
- # This will default to "bundler" if we don't specify it
67
- SyslogIdentifier=sidekiq
65
+ SyslogIdentifier=<%= sidekiq_service_unit_name %>
68
66
 
69
67
  [Install]
70
68
  WantedBy=default.target
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: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-16 00:00:00.000000000 Z
11
+ date: 2022-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -62,7 +62,6 @@ files:
62
62
  - ".gitignore"
63
63
  - ".tool-versions"
64
64
  - CHANGELOG.md
65
- - CONTRIBUTORS.md
66
65
  - Gemfile
67
66
  - LICENSE.txt
68
67
  - README.md
@@ -73,17 +72,13 @@ files:
73
72
  - lib/capistrano/sidekiq/helpers.rb
74
73
  - lib/capistrano/sidekiq/monit.rb
75
74
  - lib/capistrano/sidekiq/systemd.rb
76
- - lib/capistrano/sidekiq/upstart.rb
77
75
  - lib/capistrano/sidekiq/version.rb
78
76
  - lib/capistrano/tasks/monit.rake
79
77
  - lib/capistrano/tasks/sidekiq.rake
80
78
  - lib/capistrano/tasks/systemd.rake
81
- - lib/capistrano/tasks/upstart.rake
82
79
  - lib/generators/capistrano/sidekiq/monit/template_generator.rb
83
80
  - lib/generators/capistrano/sidekiq/monit/templates/sidekiq_monit.conf.erb
84
81
  - lib/generators/capistrano/sidekiq/systemd/templates/sidekiq.service.capistrano.erb
85
- - lib/generators/capistrano/sidekiq/upstart/templates/sidekiq.conf.erb
86
- - lib/generators/capistrano/sidekiq/upstart/templates/workers.conf.erb
87
82
  homepage: https://github.com/seuros/capistrano-sidekiq
88
83
  licenses:
89
84
  - LGPL-3.0
data/CONTRIBUTORS.md DELETED
@@ -1,11 +0,0 @@
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)
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Capistrano
4
- class Sidekiq::Upstart < Capistrano::Plugin
5
- include Sidekiq::Helpers
6
-
7
- def set_defaults
8
- set_if_empty :sidekiq_service_unit_name, 'sidekiq' # This will change in version 3.0.0 to {application}-sidekiq
9
- end
10
-
11
- def define_tasks
12
- eval_rakefile File.expand_path('../tasks/upstart.rake', __dir__)
13
- end
14
- end
15
- end
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- git_plugin = self
4
-
5
- SUPPRESS_FAILURE = %w[|| echo NO_RUNNING_INSTANCE].freeze
6
-
7
- namespace :sidekiq do
8
- desc 'Quiet sidekiq (stop fetching new tasks from Redis)'
9
- task :quiet do
10
- on roles fetch(:sidekiq_roles) do |role|
11
- git_plugin.switch_user(role) do
12
- sudo :service, fetch(:sidekiq_service_unit_name), :reload, *SUPPRESS_FAILURE
13
- end
14
- end
15
- end
16
-
17
- desc 'Stop sidekiq (graceful shutdown within timeout, put unfinished tasks back to Redis)'
18
- task :stop do
19
- on roles fetch(:sidekiq_roles) do |role|
20
- git_plugin.switch_user(role) do
21
- sudo :service, fetch(:sidekiq_service_unit_name), :stop, *SUPPRESS_FAILURE
22
- end
23
- end
24
- end
25
-
26
- desc 'Start sidekiq'
27
- task :start do
28
- on roles fetch(:sidekiq_roles) do |role|
29
- git_plugin.switch_user(role) do
30
- sudo :service, fetch(:sidekiq_service_unit_name), :start
31
- end
32
- end
33
- end
34
-
35
- desc 'Install upstart sidekiq service'
36
- task :install do
37
- on roles fetch(:sidekiq_roles) do |role|
38
- git_plugin.switch_user(role) do
39
- git_plugin.create_upstart_template
40
- end
41
- end
42
- end
43
-
44
- desc 'UnInstall upstart sidekiq service'
45
- task :uninstall do
46
- on roles fetch(:sidekiq_roles) do |role|
47
- git_plugin.switch_user(role) do
48
- execute :rm, '-f',
49
- File.join(fetch(:service_unit_path, fetch_upstart_unit_path), fetch(:sidekiq_service_unit_name))
50
- end
51
- end
52
- end
53
-
54
- desc 'Generate service_locally'
55
- task :generate_service_locally do
56
- run_locally do
57
- File.write('sidekiq.conf', git_plugin.compiled_template)
58
- end
59
- end
60
-
61
- def fetch_upstart_unit_path
62
- if fetch(:sidekiq_service_unit_user) == :system
63
- # if the path is not standard `set :service_unit_path`
64
- '/etc/init'
65
- else
66
- home_dir = backend.capture :pwd
67
- File.join(home_dir, '.config', 'upstart')
68
- end
69
- end
70
-
71
- def compiled_template
72
- search_paths = [
73
- File.expand_path(
74
- File.join(*%w[.. .. .. generators capistrano sidekiq upstart templates sidekiq.conf.erb]),
75
- __FILE__
76
- )
77
- ]
78
- template_path = search_paths.detect { |path| File.file?(path) }
79
- template = File.read(template_path)
80
- ERB.new(template).result(binding)
81
- end
82
-
83
- def create_upstart_template
84
- ctemplate = compiled_template
85
- upstart_path = fetch(:service_unit_path, fetch_upstart_unit_path)
86
-
87
- backend.execute :mkdir, '-p', upstart_path if fetch(:sidekiq_service_unit_user) != :system
88
- conf_filename = "#{fetch :sidekiq_service_unit_name}.conf"
89
- backend.upload!(
90
- StringIO.new(ctemplate),
91
- "/tmp/#{conf_filename}"
92
- )
93
- backend.execute :sudo, :mv, "/tmp/#{conf_filename}", "#{upstart_path}/#{conf_filename}"
94
- if fetch(:sidekiq_service_unit_user) == :system
95
- backend.execute :sudo, :initctl, 'reload-configuration'
96
- else
97
- # backend.execute :sudo, :initctl, 'reload-configuration' #TODO
98
- end
99
- end
100
-
101
- def num_workers
102
- fetch(:sidekiq_upstart_num_workers, nil)
103
- end
104
- end
@@ -1,78 +0,0 @@
1
- # /etc/init/sidekiq.conf - Sidekiq config | https://github.com/mperham/sidekiq/blob/master/examples/upstart/sidekiq.conf
2
-
3
- # This example config should work with Ubuntu 12.04+. It
4
- # allows you to manage multiple Sidekiq instances with
5
- # Upstart, Ubuntu's native service management tool.
6
- #
7
- # See workers.conf for how to manage all Sidekiq instances at once.
8
- #
9
- # Save this config as /etc/init/sidekiq.conf then manage sidekiq with:
10
- # sudo start <%= fetch(:sidekiq_service_unit_name) %> index=0
11
- # sudo stop <%= fetch(:sidekiq_service_unit_name) %> index=0
12
- # sudo status <%= fetch(:sidekiq_service_unit_name) %> index=0
13
- #
14
- # Hack Upstart's reload command to 'quiet' Sidekiq:
15
- #
16
- # sudo reload <%= fetch(:sidekiq_service_unit_name) %> index=0
17
- #
18
- # or use the service command:
19
- # sudo service <%= fetch(:sidekiq_service_unit_name) %> {start,stop,restart,status}
20
- #
21
-
22
- description "Sidekiq for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>"
23
-
24
- # This script is not meant to start on bootup, workers.conf
25
- # will start all sidekiq instances explicitly when it starts.
26
- #start on runlevel [2345]
27
- #stop on runlevel [06]
28
- <% if sidekiq_user %>
29
-
30
- # change to match your deployment user
31
- setuid <%= sidekiq_user %>
32
- setgid <%= sidekiq_user %>
33
- env HOME=/home/<%= sidekiq_user %>
34
- <% end %>
35
-
36
- # Greatly reduce Ruby memory fragmentation and heap usage
37
- # https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
38
- env MALLOC_ARENA_MAX=2
39
-
40
- respawn
41
- respawn limit 3 30
42
-
43
- # TERM is used when stopping sidekiq. Without declaring these as
44
- # normal exit codes, it just respawns.
45
- normal exit 0 TERM
46
-
47
- # Older versions of Upstart might not support the reload command and need
48
- # this commented out.
49
- reload signal TSTP
50
-
51
- # Upstart waits 5 seconds by default to kill a process. Increase timeout to
52
- # give sidekiq process enough time to exit.
53
- kill timeout 30
54
- <% if num_workers %>
55
-
56
- instance $index
57
- <% end %>
58
- script
59
- # this script runs in /bin/sh by default
60
- # respawn as bash so we can source in rbenv
61
- exec /bin/bash <<'EOT'
62
- # Pick your poison :) Or none if you're using a system wide installed Ruby.
63
- # rbenv
64
- # source /home/apps/.bash_profile
65
- # OR
66
- # source /home/apps/.profile
67
- # OR system:
68
- # source /etc/profile.d/rbenv.sh
69
- #
70
- # rvm
71
- # source /home/apps/.rvm/scripts/rvm
72
-
73
- # Logs out to /var/log/upstart/<%= fetch(:sidekiq_service_unit_name) %>.log by default
74
-
75
- cd <%= File.join(fetch(:deploy_to), 'current') %>
76
- exec <%= SSHKit.config.command_map[:bundle] %> exec sidekiq -e <%= fetch(:sidekiq_env) %> <%= sidekiq_config %> <%= sidekiq_concurrency %> <%= sidekiq_queues %>
77
- EOT
78
- end script
@@ -1,37 +0,0 @@
1
- # /etc/init/workers.conf - manage a set of Sidekiqs | https://github.com/mperham/sidekiq/blob/master/examples/upstart/workers.conf
2
-
3
- # This example config should work with Ubuntu 14.10 and below It
4
- # allows you to manage multiple Sidekiq instances with
5
- # Upstart, Ubuntu's native service management tool.
6
- #
7
- # See sidekiq.conf for how to manage a single Sidekiq instance.
8
- #
9
- # Use "stop workers" to stop all Sidekiq instances.
10
- # Use "start workers" to start all instances.
11
- # Use "restart workers" to restart all instances.
12
- # Crazy, right?
13
- #
14
-
15
- description "manages the set of sidekiq processes"
16
-
17
- # This starts upon bootup and stops on shutdown
18
- start on runlevel [2345]
19
- stop on runlevel [06]
20
-
21
- # Set this to the number of Sidekiq processes you want
22
- # to run on this machine
23
- env NUM_WORKERS=2
24
-
25
- pre-start script
26
- for i in `seq 1 ${NUM_WORKERS}`
27
- do
28
- start sidekiq index=$i
29
- done
30
- end script
31
-
32
- post-stop script
33
- for i in `seq 1 ${NUM_WORKERS}`
34
- do
35
- stop sidekiq index=$i
36
- done
37
- end script