lib/capistrano/sidekiq/systemd.rb in capistrano-sidekiq-2.3.1 vs lib/capistrano/sidekiq/systemd.rb in capistrano-sidekiq-3.0.0.alpha.1
- old
+ new
@@ -1,19 +1,46 @@
# frozen_string_literal: true
module Capistrano
class Sidekiq::Systemd < Capistrano::Plugin
- include Sidekiq::Helpers
-
+ include SidekiqCommon
+ def define_tasks
+ eval_rakefile File.expand_path('../tasks/systemd.rake', __dir__)
+ end
def set_defaults
- set_if_empty :sidekiq_service_unit_name, 'sidekiq' # This will change in version 3.0.0 to {application}_sidekiq_{stage}
- set_if_empty :sidekiq_service_unit_user, :user # :system
- set_if_empty :sidekiq_enable_lingering, true
- set_if_empty :sidekiq_lingering_user, nil
- set_if_empty :sidekiq_service_templates_path, 'config/deploy/templates'
+ set_if_empty :systemctl_bin, '/bin/systemctl'
+ set_if_empty :service_unit_user, :user
+ set_if_empty :systemctl_user, fetch(:service_unit_user, :user) == :user
+
+ set_if_empty :sidekiq_service_unit_name, -> { "#{fetch(:application)}_sidekiq_#{fetch(:stage)}" }
+ set_if_empty :sidekiq_lingering_user, -> { fetch(:lingering_user, fetch(:user)) }
+
+ ## Sidekiq could have a stripped down or more complex version of the environment variables
+ set_if_empty :sidekiq_service_unit_env_files, -> { fetch(:service_unit_env_files, []) }
+ set_if_empty :sidekiq_service_unit_env_vars, -> { fetch(:service_unit_env_vars, []) }
+
+ set_if_empty :sidekiq_service_templates_path, fetch(:service_templates_path, 'config/deploy/templates')
end
- def define_tasks
- eval_rakefile File.expand_path('../tasks/systemd.rake', __dir__)
+ def systemd_command(*args)
+ command = [fetch(:systemctl_bin)]
+
+ unless fetch(:service_unit_user) == :system
+ command << "--user"
+ end
+
+ command + args
+ end
+
+ def sudo_if_needed(*command)
+ if fetch(:service_unit_user) == :system
+ backend.sudo command.map(&:to_s).join(" ")
+ else
+ backend.execute(*command)
+ end
+ end
+
+ def execute_systemd(*args)
+ sudo_if_needed(*systemd_command(*args))
end
end
end