-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsolid_queue.rb
More file actions
61 lines (50 loc) · 1.9 KB
/
solid_queue.rb
File metadata and controls
61 lines (50 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true
require "capistrano/plugin"
module Capistrano
module SolidQueue
class Systemd < Capistrano::Plugin
def set_defaults
set_if_empty :solid_queue_role, "db"
set_if_empty :solid_queue_access_log, -> { File.join(shared_path, "log", "solid_queue.log") }
set_if_empty :solid_queue_error_log, -> { File.join(shared_path, "log", "solid_queue.log") }
set_if_empty :solid_queue_service_unit_name, -> { "#{fetch(:application)}_solid_queue_#{fetch(:stage)}" }
set_if_empty :solid_queue_systemd_conf_dir, -> { fetch_systemd_unit_path }
end
def define_tasks
eval_rakefile File.expand_path("../tasks/solid_queue.rake", __FILE__)
end
def register_hooks
after "deploy:starting", "solid_queue:quiet"
after "deploy:updated", "solid_queue:stop"
after "deploy:published", "solid_queue:start"
after "deploy:failed", "solid_queue:restart"
end
def execute_systemd(*args, raise_on_non_zero_exit: true)
sudo_if_needed(*systemd_command(*args), raise_on_non_zero_exit: true)
end
def sudo_if_needed(*command, raise_on_non_zero_exit: true)
if fetch(:solid_queue_systemctl_user) == :system
backend.sudo command.map(&:to_s).join(" ")
else
backend.execute(*command, raise_on_non_zero_exit: raise_on_non_zero_exit)
end
end
def systemd_command(*args)
command = ["/bin/systemctl"]
unless fetch(:solid_queue_systemctl_user) == :system
command << "--user"
end
command + args
end
def fetch_systemd_unit_path
if fetch(:solid_queue_systemctl_user) == :system
"/etc/systemd/system/"
else
home_dir = backend.capture :pwd
File.join(home_dir, ".config", "systemd", "user")
end
end
end
end
end
require_relative "solid_queue/version"