capistrano-sidekiq-systemd 0.1.0 → 0.2.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
2
  SHA256:
3
- metadata.gz: cf9409c23a84e7e446cff8abd4b7f30188cb9fa6d6f2443815ae97200bbb3967
4
- data.tar.gz: d88865d20c429021fd362137c74bb9f6a28939ba1746f917970776aeb6dcd13b
3
+ metadata.gz: ecdeef1273903466bfbf2b1c8adaf58c9185f4f120c9da54ce7bd5759c5e9c6f
4
+ data.tar.gz: 7f87a9b25213435c5e4fc12ebe94a7cd6d28cb08a858072dd3cd9ccc631e089f
5
5
  SHA512:
6
- metadata.gz: e831e9e88f1e165b52156f084f8e986adf4c3ab394526befb10af9fcbe6d95adc9b2cb6a69dc2a9b301c107ca65daa89837a1099a2180b929125542b499b4185
7
- data.tar.gz: 74b8ca37c76cf6a93098fb112958f92ed2a69dcd2af48c0e66180df8ea27b697e068da06a7c42294c26058be6ebaf6afbba32b1a0ee3f9ad12a689f5ffde2038
6
+ metadata.gz: 5d05a25aebe6bd814a0f1087e458b53ec89c2acdc864a7e31351c2ff9ec097f4663c847be0f0ec5b00b7690218f09c5c21fd03204dc2bb391056a14f3ca7d59e
7
+ data.tar.gz: 77a2ca2fd421f5c918f4f6d43347ca42fc4348efbcc8d5e18caedbdff4edcac375ef92c67b76bb03ce8d564ae3adbf82264461f640afade90d656c558693003d
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ /*.gem
data/README.md CHANGED
@@ -36,6 +36,7 @@ set :sidekiq_options_per_process, nil
36
36
  set :sidekiq_user, nil
37
37
  set :sidekiq_max_mem, nil
38
38
  set :service_unit_name, "sidekiq-#{fetch(:stage)}.service"
39
+ set :sidekiq_service_unit_user => :user # :system
39
40
  # Rbenv, Chruby, and RVM integration
40
41
  set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w[sidekiq])
41
42
  set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w[sidekiq])
@@ -1,7 +1,7 @@
1
1
  module Capistrano
2
2
  module Sidekiq
3
3
  module Systemd
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -7,6 +7,9 @@ namespace :load do
7
7
  set :sidekiq_user, nil
8
8
  set :sidekiq_max_mem, nil
9
9
  set :service_unit_name, "sidekiq-#{fetch(:stage)}.service"
10
+ set :sidekiq_service_unit_user, :user
11
+ set :sidekiq_log, nil
12
+ set :sidekiq_error_log, nil
10
13
  # Rbenv, Chruby, and RVM integration
11
14
  set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w[sidekiq])
12
15
  set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w[sidekiq])
@@ -42,7 +45,7 @@ namespace :sidekiq do
42
45
  on roles fetch(:sidekiq_roles) do |role|
43
46
  switch_user(role) do
44
47
  sidekiq_options_per_process.each_index do |index|
45
- execute :systemctl, "--user", "reload", service_unit_name(index), raise_on_non_zero_exit: false
48
+ systemctl(command: 'reload', service_unit_name: service_unit_name(index), raise_on_non_zero_exit: false)
46
49
  end
47
50
  end
48
51
  end
@@ -53,7 +56,7 @@ namespace :sidekiq do
53
56
  on roles fetch(:sidekiq_roles) do |role|
54
57
  switch_user(role) do
55
58
  sidekiq_options_per_process.each_index do |index|
56
- execute :systemctl, "--user", "stop", service_unit_name(index)
59
+ systemctl(command: 'stop', service_unit_name: service_unit_name(index))
57
60
  end
58
61
  end
59
62
  end
@@ -64,7 +67,7 @@ namespace :sidekiq do
64
67
  on roles fetch(:sidekiq_roles) do |role|
65
68
  switch_user(role) do
66
69
  sidekiq_options_per_process.each_index do |index|
67
- execute :systemctl, "--user", "start", service_unit_name(index)
70
+ systemctl(command: 'start', service_unit_name: service_unit_name(index))
68
71
  end
69
72
  end
70
73
  end
@@ -82,7 +85,7 @@ namespace :sidekiq do
82
85
  switch_user(role) do
83
86
  create_systemd_template(role)
84
87
  sidekiq_options_per_process.each_index do |index|
85
- execute :systemctl, "--user", "enable", service_unit_name(index)
88
+ systemctl(command: 'enable', service_unit_name: service_unit_name(index))
86
89
  end
87
90
  end
88
91
  end
@@ -93,8 +96,8 @@ namespace :sidekiq do
93
96
  on roles fetch(:sidekiq_roles) do |role|
94
97
  switch_user(role) do
95
98
  sidekiq_options_per_process.each_index do |index|
96
- execute :systemctl, "--user", "disable", service_unit_name(index)
97
- execute :rm, File.join(fetch(:service_unit_path, File.join(capture(:pwd), ".config", "systemd", "user")),service_unit_name(index))
99
+ systemctl(command: 'disable', service_unit_name: service_unit_name(index))
100
+ execute :rm, File.join(fetch(:service_unit_path, fetch_systemd_unit_path(capture(:pwd))), service_unit_name(index))
98
101
  end
99
102
  end
100
103
  end
@@ -103,13 +106,17 @@ namespace :sidekiq do
103
106
  def create_systemd_template(role)
104
107
  template = File.read(File.expand_path('../../../../generators/capistrano/sidekiq/systemd/templates/sidekiq.service.capistrano.erb', __FILE__))
105
108
  home_dir = capture :pwd
106
- systemd_path = fetch(:service_unit_path, File.join(home_dir, ".config", "systemd", "user"))
109
+ systemd_path = fetch(:service_unit_path, fetch_systemd_unit_path(home_dir))
107
110
  sidekiq_cmd = SSHKit.config.command_map[:sidekiq].gsub('~', home_dir)
108
- execute :mkdir, "-p", systemd_path
111
+ if fetch(:sidekiq_service_unit_user) == :user
112
+ execute :mkdir, "-p", systemd_path
113
+ end
109
114
  sidekiq_options_per_process.each_index do |index|
110
- upload!(StringIO.new(ERB.new(template).result(binding)), "#{systemd_path}/#{service_unit_name(index)}")
115
+ upload_template(data: StringIO.new(ERB.new(template).result(binding)),
116
+ systemd_path: systemd_path, service_unit_name: service_unit_name(index)
117
+ )
111
118
  end
112
- execute :systemctl, "--user", "daemon-reload"
119
+ systemctl(command: 'daemon-reload')
113
120
  end
114
121
 
115
122
  def process_options(index = 0)
@@ -183,6 +190,33 @@ namespace :sidekiq do
183
190
  end
184
191
  end
185
192
 
193
+ def systemctl(command:, service_unit_name: nil, raise_on_non_zero_exit: true)
194
+ if fetch(:sidekiq_service_unit_user) == :user
195
+ execute :systemctl, "--user", command, service_unit_name, raise_on_non_zero_exit: raise_on_non_zero_exit
196
+ elsif fetch(:sidekiq_service_unit_user) == :system
197
+ execute :sudo, :systemctl, command, service_unit_name, raise_on_non_zero_exit: raise_on_non_zero_exit
198
+ end
199
+ end
200
+
201
+ def fetch_systemd_unit_path(home_dir)
202
+ if fetch(:sidekiq_service_unit_user) == :user
203
+ File.join(home_dir, ".config", "systemd", "user")
204
+ elsif fetch(:sidekiq_service_unit_user) == :system
205
+ File.join("/", "etc", "systemd", "system")
206
+ end
207
+ end
208
+
209
+ def upload_template(data:, systemd_path:, service_unit_name:)
210
+ temp_file_path = File.join('/', 'tmp', "#{service_unit_name}")
211
+ upload!(data, temp_file_path)
212
+ if fetch(:sidekiq_service_unit_user) == :system
213
+ execute :sudo, :mv, temp_file_path, File.join(systemd_path, service_unit_name)
214
+ else
215
+ execute :mv, temp_file_path, File.join(systemd_path, service_unit_name)
216
+ end
217
+ systemctl(command: 'daemon-reload')
218
+ end
219
+
186
220
  def multiple_processes?
187
221
  fetch(:sidekiq_options_per_process) && fetch(:sidekiq_options_per_process).size > 1
188
222
  end
@@ -9,6 +9,9 @@ WorkingDirectory=<%= fetch(:deploy_to) %>/current
9
9
  ExecStart=<%= sidekiq_cmd %> <%= process_options(index) %>
10
10
  ExecReload=/bin/kill -TSTP $MAINPID
11
11
  ExecStop=/bin/kill -TERM $MAINPID
12
+ <%="StandardOutput=append:#{fetch(:sidekiq_log)}" if fetch(:sidekiq_log) %>
13
+ <%="StandardError=append:#{fetch(:sidekiq_error_log)}" if fetch(:sidekiq_error_log) %>
14
+ <%="User=#{sidekiq_user(role)}" if sidekiq_user(role) %>
12
15
  <%= "MemoryAccounting=#{ !!max_mem(index) }" if max_mem(index) %>
13
16
  <%= "MemoryLimit=#{ max_mem(index) }" if max_mem(index) %>
14
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-sidekiq-systemd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - spilin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-04 00:00:00.000000000 Z
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -57,7 +57,7 @@ metadata:
57
57
  homepage_uri: https://github.com/spilin/capistrano-sidekiq-systemd
58
58
  source_code_uri: https://github.com/spilin/capistrano-sidekiq-systemd
59
59
  changelog_uri: https://github.com/spilin/capistrano-sidekiq-systemd/CHANGELOG.md
60
- post_install_message:
60
+ post_install_message:
61
61
  rdoc_options: []
62
62
  require_paths:
63
63
  - lib
@@ -72,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
- rubygems_version: 3.0.6
76
- signing_key:
75
+ rubygems_version: 3.2.15
76
+ signing_key:
77
77
  specification_version: 4
78
78
  summary: Capistrano sidekiq systemd support
79
79
  test_files: []