Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert many changes that break systemd #308

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ And then execute:

$ bundle


## Usage
```ruby
# Capfile
Expand All @@ -25,7 +24,6 @@ And then execute:
install_plugin Capistrano::Sidekiq::Monit # tests needed
```


Configurable options - Please ensure you check your version's branch for the available settings - shown here with defaults:

```ruby
Expand Down Expand Up @@ -65,6 +63,11 @@ Configurable options - Please ensure you check your version's branch for the ava
```
See `capistrano/sidekiq/helpers.rb` for other undocumented configuration settings.

## Upgrading and reconfiguring

When upgrading or reconfiguring the `sidekiq_processes` option you must run
`sidekiq:uninstall` before and `sidekiq:install` after.

## Bundler

If you'd like to prepend `bundle exec` to your sidekiq and sidekiqctl calls, modify the SSHKit command maps
Expand All @@ -74,7 +77,6 @@ SSHKit.config.command_map[:sidekiq] = "bundle exec sidekiq"
SSHKit.config.command_map[:sidekiqctl] = "bundle exec sidekiqctl"
```


## Customizing the monit sidekiq templates

If you need change some config in redactor, you can
Expand Down
1 change: 1 addition & 0 deletions lib/capistrano/sidekiq/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ def sidekiq_user(role = nil)
def expanded_bundle_path
backend.capture(:echo, SSHKit.config.command_map[:bundle]).strip
end

end
end
1 change: 1 addition & 0 deletions lib/capistrano/tasks/sidekiq.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace :sidekiq do
task :add_default_hooks do
after 'deploy:starting', 'sidekiq:quiet' if Rake::Task.task_defined?('sidekiq:quiet')
after 'deploy:updated', 'sidekiq:stop'
after 'deploy:reverted', 'sidekiq:stop'
after 'deploy:published', 'sidekiq:start'
after 'deploy:failed', 'sidekiq:restart'
end
Expand Down
54 changes: 29 additions & 25 deletions lib/capistrano/tasks/systemd.rake
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,18 @@ namespace :sidekiq do
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

if sidekiq_processes > 1
range = 1..sidekiq_processes
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'
else
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
backend.execute :mv, temp_file_name, systemd_file_name
backend.execute :systemctl, '--user', 'daemon-reload'
end
end

Expand Down Expand Up @@ -203,14 +196,14 @@ namespace :sidekiq do
def systemctl_command(*args, process: nil)
execute_array =
if fetch(:sidekiq_service_unit_user) == :system
%i[sudo systemctl]
[:sudo, :systemctl]
else
[:systemctl, '--user']
end
if process && sidekiq_processes > 1
if process
execute_array.push(
*args, sidekiq_service_unit_name(process: process)
).flatten
).flatten
else
execute_array.push(*args, sidekiq_service_unit_name).flatten
end
Expand Down Expand Up @@ -261,14 +254,21 @@ namespace :sidekiq do
end.join(' ')
end

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"
def sidekiq_service_file_name
if sidekiq_processes > 1
"#{fetch(:sidekiq_service_unit_name)}@.service"
else
"#{fetch(:sidekiq_service_unit_name)}.service"
end
end

def sidekiq_service_unit_name(process: nil)
if process && sidekiq_processes > 1
"#{fetch(:sidekiq_service_unit_name)}@#{process}"
if sidekiq_processes > 1
if process
"#{fetch(:sidekiq_service_unit_name)}@#{process}"
else
"#{fetch(:sidekiq_service_unit_name)}@{1..#{sidekiq_processes}}"
end
else
fetch(:sidekiq_service_unit_name)
end
Expand All @@ -277,7 +277,11 @@ namespace :sidekiq do
# process = 1 | sidekiq_systemd_1.yaml
# process = nil | sidekiq_systemd_%i.yaml
def sidekiq_systemd_config_name(process = nil)
"sidekiq_systemd_#{(process&.to_s || '%i')}.yaml"
if sidekiq_processes > 1
"sidekiq_systemd_#{(process&.to_s || '%i')}.yaml"
else
'sidekiq_systemd.yaml'
end
end

def config_per_process?
Expand Down