Skip to content

Commit 8c774da

Browse files
authored
Make system user work
1 parent c86cd13 commit 8c774da

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/capistrano/solid_queue.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,25 @@ def register_hooks
2525
end
2626

2727
def execute_systemd(*args, raise_on_non_zero_exit: true)
28-
command = ["/bin/systemctl", "--user"] + args
29-
backend.execute(*command, raise_on_non_zero_exit: raise_on_non_zero_exit)
28+
sudo_if_needed(*systemd_command(*args), raise_on_non_zero_exit: true)
29+
end
30+
31+
def sudo_if_needed(*command, raise_on_non_zero_exit: true)
32+
if fetch(:solid_queue_systemctl_user) == :system
33+
backend.sudo command.map(&:to_s).join(" ")
34+
else
35+
backend.execute(*command, raise_on_non_zero_exit: raise_on_non_zero_exit)
36+
end
37+
end
38+
39+
def systemd_command(*args)
40+
command = ['/bin/systemctl']
41+
42+
unless fetch(:solid_queue_systemctl_user) == :system
43+
command << "--user"
44+
end
45+
46+
command + args
3047
end
3148

3249
def fetch_systemd_unit_path

0 commit comments

Comments
 (0)