lib/capistrano/tasks/systemd.rake in capistrano-sidekiq-2.2.0 vs lib/capistrano/tasks/systemd.rake in capistrano-sidekiq-2.3.0
- old
+ new
@@ -144,23 +144,30 @@
end
def create_systemd_template
ctemplate = compiled_template
systemd_path = fetch(:service_unit_path, fetch_systemd_unit_path)
- systemd_file_name = File.join(systemd_path, sidekiq_service_file_name)
-
backend.execute :mkdir, '-p', systemd_path if fetch(:sidekiq_service_unit_user) == :user
- temp_file_name = File.join('/tmp', sidekiq_service_file_name)
- backend.upload!(StringIO.new(ctemplate), temp_file_name)
- if fetch(:sidekiq_service_unit_user) == :system
- backend.execute :sudo, :mv, temp_file_name, systemd_file_name
- backend.execute :sudo, :systemctl, 'daemon-reload'
+ if sidekiq_processes > 1
+ range = 1..sidekiq_processes
else
- backend.execute :mv, temp_file_name, systemd_file_name
- backend.execute :systemctl, '--user', 'daemon-reload'
+ range = 0..0
end
+ range.each do |index|
+ temp_file_name = File.join('/tmp', sidekiq_service_file_name(index))
+ systemd_file_name = File.join(systemd_path, sidekiq_service_file_name(index))
+ backend.upload!(StringIO.new(ctemplate), temp_file_name)
+
+ if fetch(:sidekiq_service_unit_user) == :system
+ backend.execute :sudo, :mv, temp_file_name, systemd_file_name
+ backend.execute :sudo, :systemctl, 'daemon-reload'
+ else
+ backend.execute :mv, temp_file_name, systemd_file_name
+ backend.execute :systemctl, '--user', 'daemon-reload'
+ end
+ end
end
def create_systemd_config_symlink(process)
config = fetch(:sidekiq_config)
return unless config
@@ -198,12 +205,11 @@
if fetch(:sidekiq_service_unit_user) == :system
%i[sudo systemctl]
else
[:systemctl, '--user']
end
-
- if process
+ if process && sidekiq_processes > 1
execute_array.push(
*args, sidekiq_service_unit_name(process: process)
).flatten
else
execute_array.push(*args, sidekiq_service_unit_name).flatten
@@ -253,29 +259,26 @@
Array(fetch(:sidekiq_queue)).map do |queue|
"--queue #{queue}"
end.join(' ')
end
- def sidekiq_service_file_name
- "#{fetch(:sidekiq_service_unit_name)}.service"
+ def sidekiq_service_file_name(index = nil)
+ return "#{fetch(:sidekiq_service_unit_name)}.service" if index.to_i.zero?
+ "#{fetch(:sidekiq_service_unit_name)}@#{index}.service"
end
def sidekiq_service_unit_name(process: nil)
- if process
+ if process && sidekiq_processes > 1
"#{fetch(:sidekiq_service_unit_name)}@#{process}"
- elsif sidekiq_processes > 1
- "#{fetch(:sidekiq_service_unit_name)}@{1..#{sidekiq_processes}}"
else
fetch(:sidekiq_service_unit_name)
end
end
# process = 1 | sidekiq_systemd_1.yaml
# process = nil | sidekiq_systemd_%i.yaml
def sidekiq_systemd_config_name(process = nil)
- file_name = 'sidekiq_systemd_'
- file_name << (process&.to_s || '%i')
- "#{file_name}.yaml"
+ "sidekiq_systemd_#{(process&.to_s || '%i')}.yaml"
end
def config_per_process?
fetch(:sidekiq_config).is_a?(Array)
end