Exec over ssh with accessory
This commit is contained in:
@@ -83,11 +83,23 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
desc "exec [NAME] [CMD]", "Execute a custom command on accessory host"
|
desc "exec [NAME] [CMD]", "Execute a custom command on accessory host"
|
||||||
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 container / [run] perform in new container / [ssh] perform over ssh"
|
||||||
def exec(name, cmd)
|
def exec(name, cmd)
|
||||||
with_accessory(name) do |accessory|
|
runner = \
|
||||||
runner = options[:run] ? :run_exec : :exec
|
case options[:method]
|
||||||
on(accessory.host) { |host| puts_by_host host, capture_with_info(*accessory.send(runner, cmd)) }
|
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 #{accessory.host}"
|
||||||
|
exec accessory.exec_over_ssh(cmd, host: accessory.host)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
on(accessory.host) { puts capture_with_info(*accessory.send(runner, cmd) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ class Mrsk::Commands::Accessory < 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 bash(host:)
|
def bash(host:)
|
||||||
exec_over_ssh "bash", host: host
|
exec_over_ssh "bash", host: host
|
||||||
end
|
end
|
||||||
@@ -94,10 +98,6 @@ class Mrsk::Commands::Accessory < 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=#{service_name}" ]
|
[ "--filter", "label=service=#{service_name}" ]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user