Extract proper auditor and audit everything
This commit is contained in:
@@ -9,7 +9,10 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
||||
with_accessory(name) do |accessory|
|
||||
directories(name)
|
||||
upload(name)
|
||||
on(accessory.host) { execute *accessory.run }
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} boot"), verbosity: :debug
|
||||
execute *accessory.run
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -18,6 +21,8 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
||||
def upload(name)
|
||||
with_accessory(name) do |accessory|
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} upload files"), verbosity: :debug
|
||||
|
||||
accessory.files.each do |(local, remote)|
|
||||
accessory.ensure_local_file_present(local)
|
||||
|
||||
@@ -33,6 +38,8 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
||||
def directories(name)
|
||||
with_accessory(name) do |accessory|
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} create directories"), verbosity: :debug
|
||||
|
||||
accessory.directories.keys.each do |host_path|
|
||||
execute *accessory.make_directory(host_path)
|
||||
end
|
||||
@@ -52,14 +59,20 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
||||
desc "start [NAME]", "Start existing accessory on host"
|
||||
def start(name)
|
||||
with_accessory(name) do |accessory|
|
||||
on(accessory.host) { execute *accessory.start }
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} start"), verbosity: :debug
|
||||
execute *accessory.start
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "stop [NAME]", "Stop accessory on host"
|
||||
def stop(name)
|
||||
with_accessory(name) do |accessory|
|
||||
on(accessory.host) { execute *accessory.stop, raise_on_non_zero_exit: false }
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} stop"), verbosity: :debug
|
||||
execute *accessory.stop, raise_on_non_zero_exit: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -98,11 +111,17 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
||||
|
||||
when options[:reuse]
|
||||
say "Launching command from existing container...", :magenta
|
||||
on(accessory.host) { capture_with_info(*accessory.execute_in_existing_container(cmd)) }
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} cmd '#{cmd}'"), verbosity: :debug
|
||||
capture_with_info(*accessory.execute_in_existing_container(cmd))
|
||||
end
|
||||
|
||||
else
|
||||
say "Launching command from new container...", :magenta
|
||||
on(accessory.host) { capture_with_info(*accessory.execute_in_new_container(cmd)) }
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} cmd '#{cmd}'"), verbosity: :debug
|
||||
capture_with_info(*accessory.execute_in_new_container(cmd))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -150,21 +169,30 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
||||
desc "remove_container [NAME]", "Remove accessory container from host"
|
||||
def remove_container(name)
|
||||
with_accessory(name) do |accessory|
|
||||
on(accessory.host) { execute *accessory.remove_container }
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} remove container"), verbosity: :debug
|
||||
execute *accessory.remove_container
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "remove_image [NAME]", "Remove accessory image from host"
|
||||
def remove_image(name)
|
||||
with_accessory(name) do |accessory|
|
||||
on(accessory.host) { execute *accessory.remove_image }
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} remove image"), verbosity: :debug
|
||||
execute *accessory.remove_image
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "remove_service_directory [NAME]", "Remove accessory directory used for uploaded files and data directories from host"
|
||||
def remove_service_directory(name)
|
||||
with_accessory(name) do |accessory|
|
||||
on(accessory.host) { execute *accessory.remove_service_directory }
|
||||
on(accessory.host) do
|
||||
execute *MRSK.auditor.record("accessory #{name} remove service directory"), verbosity: :debug
|
||||
execute *accessory.remove_service_directory
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
||||
|
||||
MRSK.config.roles.each do |role|
|
||||
on(role.hosts) do |host|
|
||||
execute *MRSK.auditor.record("app boot version #{version}"), verbosity: :debug
|
||||
|
||||
begin
|
||||
execute *MRSK.app.run(role: role.name)
|
||||
rescue SSHKit::Command::Failed => e
|
||||
@@ -33,12 +35,18 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
||||
|
||||
desc "start", "Start existing app on servers (use --version=<git-hash> to designate specific version)"
|
||||
def start
|
||||
on(MRSK.hosts) { execute *MRSK.app.start, raise_on_non_zero_exit: false }
|
||||
on(MRSK.hosts) do
|
||||
execute *MRSK.auditor.record("app start version #{MRSK.version}"), verbosity: :debug
|
||||
execute *MRSK.app.start, raise_on_non_zero_exit: false
|
||||
end
|
||||
end
|
||||
|
||||
desc "stop", "Stop app on servers"
|
||||
def stop
|
||||
on(MRSK.hosts) { execute *MRSK.app.stop, raise_on_non_zero_exit: false }
|
||||
on(MRSK.hosts) do
|
||||
execute *MRSK.auditor.record("app stop"), verbosity: :debug
|
||||
execute *MRSK.app.stop, raise_on_non_zero_exit: false
|
||||
end
|
||||
end
|
||||
|
||||
desc "details", "Display details about app containers"
|
||||
@@ -68,15 +76,22 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
||||
when options[:reuse]
|
||||
say "Get current version of running container...", :magenta unless options[:version]
|
||||
using_version(options[:version] || current_running_version) do |version|
|
||||
say "Launching command with version #{version} from existing container on #{MRSK.primary_host}...", :magenta
|
||||
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.execute_in_existing_container(cmd)) }
|
||||
say "Launching command with version #{version} from existing container...", :magenta
|
||||
|
||||
on(MRSK.hosts) do |host|
|
||||
execute *MRSK.auditor.record("app cmd '#{cmd}' with version #{version}"), verbosity: :debug
|
||||
puts_by_host host, capture_with_info(*MRSK.app.execute_in_existing_container(cmd))
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
say "Get most recent version available as an image...", :magenta unless options[:version]
|
||||
using_version(options[:version] || most_recent_version_available) do |version|
|
||||
say "Launching command with version #{version} from new container on #{MRSK.primary_host}...", :magenta
|
||||
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.execute_in_new_container(cmd)) }
|
||||
say "Launching command with version #{version} from new container...", :magenta
|
||||
on(MRSK.hosts) do |host|
|
||||
execute *MRSK.auditor.record("app cmd '#{cmd}' with version #{version}"), verbosity: :debug
|
||||
puts_by_host host, capture_with_info(*MRSK.app.execute_in_new_container(cmd))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -134,17 +149,26 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
||||
|
||||
desc "remove_container [VERSION]", "Remove app container with given version from servers"
|
||||
def remove_container(version)
|
||||
on(MRSK.hosts) { execute *MRSK.app.remove_container(version: version) }
|
||||
on(MRSK.hosts) do
|
||||
execute *MRSK.auditor.record("app remove container #{version}"), verbosity: :debug
|
||||
execute *MRSK.app.remove_container(version: version)
|
||||
end
|
||||
end
|
||||
|
||||
desc "remove_containers", "Remove all app containers from servers"
|
||||
def remove_containers
|
||||
on(MRSK.hosts) { execute *MRSK.app.remove_containers }
|
||||
on(MRSK.hosts) do
|
||||
execute *MRSK.auditor.record("app remove containers"), verbosity: :debug
|
||||
execute *MRSK.app.remove_containers
|
||||
end
|
||||
end
|
||||
|
||||
desc "remove_images", "Remove all app images from servers"
|
||||
def remove_images
|
||||
on(MRSK.hosts) { execute *MRSK.app.remove_images }
|
||||
on(MRSK.hosts) do
|
||||
execute *MRSK.auditor.record("app remove images"), verbosity: :debug
|
||||
execute *MRSK.app.remove_images
|
||||
end
|
||||
end
|
||||
|
||||
desc "current_version", "Shows the version currently running"
|
||||
|
||||
@@ -30,7 +30,10 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
|
||||
|
||||
desc "pull", "Pull app image from the registry onto servers"
|
||||
def pull
|
||||
on(MRSK.hosts) { execute *MRSK.builder.pull }
|
||||
on(MRSK.hosts) do
|
||||
execute *MRSK.auditor.record("build pull image #{MRSK.version}"), verbosity: :debug
|
||||
execute *MRSK.builder.pull
|
||||
end
|
||||
end
|
||||
|
||||
desc "create", "Create a local build setup"
|
||||
|
||||
@@ -70,6 +70,13 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
invoke "mrsk:cli:accessory:details", [ "all" ]
|
||||
end
|
||||
|
||||
desc "audit", "Show audit log from servers"
|
||||
def audit
|
||||
on(MRSK.hosts) do |host|
|
||||
puts_by_host host, capture_with_info(*MRSK.auditor.reveal)
|
||||
end
|
||||
end
|
||||
|
||||
desc "config", "Show combined config"
|
||||
def config
|
||||
run_locally do
|
||||
|
||||
@@ -9,11 +9,17 @@ class Mrsk::Cli::Prune < Mrsk::Cli::Base
|
||||
|
||||
desc "images", "Prune unused images older than 30 days"
|
||||
def images
|
||||
on(MRSK.hosts) { execute *MRSK.prune.images }
|
||||
on(MRSK.hosts) do
|
||||
execute *MRSK.auditor.record("prune images"), verbosity: :debug
|
||||
execute *MRSK.prune.images
|
||||
end
|
||||
end
|
||||
|
||||
desc "containers", "Prune stopped containers for the service older than 3 days"
|
||||
def containers
|
||||
on(MRSK.hosts) { execute *MRSK.prune.containers }
|
||||
on(MRSK.hosts) do
|
||||
execute *MRSK.auditor.record("prune containers"), verbosity: :debug
|
||||
execute *MRSK.prune.containers
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,12 +15,18 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
|
||||
|
||||
desc "start", "Start existing Traefik on servers"
|
||||
def start
|
||||
on(MRSK.traefik_hosts) { execute *MRSK.traefik.start, raise_on_non_zero_exit: false }
|
||||
on(MRSK.traefik_hosts) do
|
||||
execute *MRSK.auditor.record("traefik start"), verbosity: :debug
|
||||
execute *MRSK.traefik.start, raise_on_non_zero_exit: false
|
||||
end
|
||||
end
|
||||
|
||||
desc "stop", "Stop Traefik on servers"
|
||||
def stop
|
||||
on(MRSK.traefik_hosts) { execute *MRSK.traefik.stop, raise_on_non_zero_exit: false }
|
||||
on(MRSK.traefik_hosts) do
|
||||
execute *MRSK.auditor.record("traefik stop"), verbosity: :debug
|
||||
execute *MRSK.traefik.stop, raise_on_non_zero_exit: false
|
||||
end
|
||||
end
|
||||
|
||||
desc "restart", "Restart Traefik on servers"
|
||||
@@ -67,11 +73,17 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
|
||||
|
||||
desc "remove_container", "Remove Traefik container from servers"
|
||||
def remove_container
|
||||
on(MRSK.traefik_hosts) { execute *MRSK.traefik.remove_container }
|
||||
on(MRSK.traefik_hosts) do
|
||||
execute *MRSK.auditor.record("traefik remove container"), verbosity: :debug
|
||||
execute *MRSK.traefik.remove_container
|
||||
end
|
||||
end
|
||||
|
||||
desc "remove_container", "Remove Traefik image from servers"
|
||||
def remove_image
|
||||
on(MRSK.traefik_hosts) { execute *MRSK.traefik.remove_image }
|
||||
on(MRSK.traefik_hosts) do
|
||||
execute *MRSK.auditor.record("traefik remove image"), verbosity: :debug
|
||||
execute *MRSK.traefik.remove_image
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user