Class: Linecook::Commands::Run

Inherits:
Linecook::Command show all
Includes:
Linecook::CommandUtils
Defined in:
lib/linecook/commands/run.rb

Overview

:startdoc::desc run packages

Runs packages on remote hosts by transfering a package directory using scp, and then executing one or more scripts via ssh. Run is configured using an ssh config file, which should contain all necessary ssh options.

Packages are transfered to hosts based on the basename of the package, hence ‘path/to/abox’ will run on the ‘abox’ host as configured in the ssh config file.

Constant Summary collapse

RUN_SCRIPT =
File.expand_path('../../../../bin/linecook_run', __FILE__)
SCP_SCRIPT =
File.expand_path('../../../../bin/linecook_scp', __FILE__)

Instance Method Summary collapse

Methods included from Linecook::CommandUtils

#sh, #sh!

Methods inherited from Linecook::Command

#call, help, #initialize, parse, signature

Constructor Details

This class inherits a constructor from Linecook::Command

Instance Method Details

#format(opts) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/linecook/commands/run.rb', line 51

def format(opts)
  options = []

  opts.each_pair do |key, value|
    next if value.to_s.strip.empty?

    case value
    when true
      options << "-#{key}"
    when false
    else
      options << "-#{key} '#{value}'"
    end
  end

  options.sort.join(' ')
end

#full_path_to_remote_dirObject



30
31
32
# File 'lib/linecook/commands/run.rb', line 30

def full_path_to_remote_dir
  (remote_dir[0] == ?/ ? remote_dir : "$(pwd)/#{remote_dir}").chomp('/')
end

#process(*package_dirs) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/linecook/commands/run.rb', line 34

def process(*package_dirs)
  opts = {
    'D' => full_path_to_remote_dir,
    'F' => ssh_config_file,
    'x' => xtrace
  }

  if scp
    sh! "sh #{SCP_SCRIPT} #{format(opts)} #{package_dirs.join(' ')}"
  end

  remote_scripts.each do |remote_script|
    script_opts = {'S' => remote_script}.merge(opts)
    sh! "sh #{RUN_SCRIPT} #{format(script_opts)} #{package_dirs.join(' ')}"
  end
end