diff --git a/lib/mrsk/cli/app.rb b/lib/mrsk/cli/app.rb index efd0dc38..70787cdd 100644 --- a/lib/mrsk/cli/app.rb +++ b/lib/mrsk/cli/app.rb @@ -130,11 +130,13 @@ class Mrsk::Cli::App < Mrsk::Cli::Base with_lock do stop = options[:stop] + cli = self + on(MRSK.hosts) do |host| roles = MRSK.roles_on(host) roles.each do |role| - stale_versions(role: role).each do |version| + cli.stale_versions(host: host, role: role).each do |version| if stop puts_by_host host, "Stopping stale container for role #{role} with version #{version}" execute *MRSK.app(role: role).stop(version: version), raise_on_non_zero_exit: false @@ -242,6 +244,17 @@ class Mrsk::Cli::App < Mrsk::Cli::Base on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.current_running_version).strip } end + def stale_versions(host:, role:) + stale_versions = nil + on(host) do + stale_versions = \ + capture_with_info(*MRSK.app(role: role).list_versions, raise_on_non_zero_exit: false) + .split("\n") + .drop(1) + end + stale_versions + end + private def using_version(new_version) if new_version diff --git a/lib/mrsk/sshkit_with_ext.rb b/lib/mrsk/sshkit_with_ext.rb index d657a07c..075c2643 100644 --- a/lib/mrsk/sshkit_with_ext.rb +++ b/lib/mrsk/sshkit_with_ext.rb @@ -1,17 +1,7 @@ require "sshkit" require "sshkit/dsl" -module AppHelper - def stale_versions(role:) - capture_with_info(*MRSK.app(role: role).list_versions, raise_on_non_zero_exit: false) - .split("\n") - .drop(1) - end -end - class SSHKit::Backend::Abstract - include AppHelper - def capture_with_info(*args, **kwargs) capture(*args, **kwargs, verbosity: Logger::INFO) end