Execute over SSH too
This commit is contained in:
@@ -40,10 +40,24 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
desc "exec [CMD]", "Execute a custom command on servers"
|
desc "exec [CMD]", "Execute a custom command on servers"
|
||||||
option :run, type: :boolean, default: false, desc: "Start a new container to run the command rather than reusing existing"
|
option :method, aliases: "-m", default: "exec", desc: "Execution method: [exec] perform inside app container / [run] perform in new container / [ssh] perform over ssh"
|
||||||
def exec(cmd)
|
def exec(cmd)
|
||||||
runner = options[:run] ? :run_exec : :exec
|
runner = \
|
||||||
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.send(runner, cmd)) }
|
case options[:method]
|
||||||
|
when "exec" then "exec"
|
||||||
|
when "run" then "run_exec"
|
||||||
|
when "ssh" then "exec_over_ssh"
|
||||||
|
else raise "Unknown method: #{options[:method]}"
|
||||||
|
end.inquiry
|
||||||
|
|
||||||
|
if runner.exec_over_ssh?
|
||||||
|
run_locally do
|
||||||
|
info "Launching command on #{MRSK.primary_host}"
|
||||||
|
exec MRSK.app.exec_over_ssh(cmd, host: MRSK.primary_host)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.send(runner, cmd)) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "console", "Start Rails Console on primary host (or specific host set by --hosts)"
|
desc "console", "Start Rails Console on primary host (or specific host set by --hosts)"
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
*command
|
*command
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exec_over_ssh(*command, host:)
|
||||||
|
run_over_ssh run_exec(*command, interactive: true).join(" "), host: host
|
||||||
|
end
|
||||||
|
|
||||||
def follow_logs(host:, grep: nil)
|
def follow_logs(host:, grep: nil)
|
||||||
run_over_ssh pipe(
|
run_over_ssh pipe(
|
||||||
current_container_id,
|
current_container_id,
|
||||||
@@ -89,10 +93,6 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def exec_over_ssh(*command, host:)
|
|
||||||
run_over_ssh run_exec(*command, interactive: true).join(" "), host: host
|
|
||||||
end
|
|
||||||
|
|
||||||
def service_filter
|
def service_filter
|
||||||
[ "--filter", "label=service=#{config.service}" ]
|
[ "--filter", "label=service=#{config.service}" ]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user