class DRbQS::Manage::SSHExecute

Constants

COMMAND_DRBQS_NODE
COMMAND_DRBQS_SERVER
COMMAND_FILENAME_CREATE
COMMAND_NICE

Public Class Methods

new(dest, opts = {}) click to toggle source

@param [String] dest Destination name @param [Hash] opts Option hash @option opts [boolean] :bundler Use bundler to execute commands: filename-create, drbqs-server, and drbqs-node @option opts [String] :shell Same as options DRbQS::Manage::SSHShell @option opts [String] :keys Same as options DRbQS::Manage::SSHShell @option opts [IO] :io Same as options DRbQS::Manage::SSHShell @option opts [String] :directory Same as options DRbQS::Manage::SSHShell @option opts [String] :rvm Same as options DRbQS::Manage::SSHShell @option opts [String] :rvm_init Same as options DRbQS::Manage::SSHShell @option opts [Hash] :env Same as options DRbQS::Manage::SSHShell

# File lib/drbqs/manage/ssh_execute.rb, line 21
def initialize(dest, opts = {})
  @ssh_host = DRbQS::Config.new.ssh_host
  opts = opts.dup
  path, options = @ssh_host.get_options(dest)
  dest = options.delete(:dest) || dest
  @bundler = opts.delete(:bundler)
  @ssh_shell = DRbQS::Manage::SSHShell.new(dest, options.merge(opts))
end

Public Instance Methods

command(command) click to toggle source
# File lib/drbqs/manage/ssh_execute.rb, line 30
def command(command)
  @ssh_shell.execute_all(command)
end
get_environment() click to toggle source
# File lib/drbqs/manage/ssh_execute.rb, line 34
def get_environment
  @ssh_shell.get_environment
end
node(cmd_options, opts = {}) click to toggle source

Add options –daemon and –log-prefix.

# File lib/drbqs/manage/ssh_execute.rb, line 79
def node(cmd_options, opts = {})
  ret = nil
  @ssh_shell.start do |sh|
    dir = create_new_directory(sh, opts[:daemon] || 'drbqs_node_log')
    cmd = add_command_options(command_ruby(COMMAND_DRBQS_NODE), File.join(dir, 'daemon_node.log'), opts[:nice])
    cmd << ' --log-prefix ' << File.join(dir, 'node') << ' ' << cmd_options.join(' ')
    process, result = sh.exec(cmd)
    ret = (process.exit_status == 0)
  end
  ret
end
server(cmd_options, opts = {}) click to toggle source

Add options –daemon and –log-file.

# File lib/drbqs/manage/ssh_execute.rb, line 65
def server(cmd_options, opts = {})
  ret = nil
  @ssh_shell.start do |sh|
    dir = create_new_directory(sh, opts[:daemon] || 'drbqs_server_log')
    cmd = add_command_options(command_ruby(COMMAND_DRBQS_SERVER), File.join(dir, 'daemon_server.log'), opts[:nice])
    cmd << " --log-file " << File.join(dir, 'server.log') << ' '
    cmd << cmd_options.join(' ')
    process, result = sh.exec(cmd)
    ret = (process.exit_status == 0)
  end
  ret
end

Private Instance Methods

add_command_options(cmd, daemon, nice) click to toggle source

Keys are :nice and :daemon.

# File lib/drbqs/manage/ssh_execute.rb, line 48
def add_command_options(cmd, daemon, nice)
  s = ''
  if nice
    s << "nice "
    s << "-n #{nice.to_s} " if Integer === nice
  end
  s << cmd << " --daemon " << daemon
end
command_ruby(cmd) click to toggle source

Add “bundle exec” if bundler is true

# File lib/drbqs/manage/ssh_execute.rb, line 39
def command_ruby(cmd)
  if @bundler
    cmd = "bundle exec #{cmd}"
  end
  cmd
end
create_new_directory(sh, dir) click to toggle source
# File lib/drbqs/manage/ssh_execute.rb, line 58
def create_new_directory(sh, dir)
  process, result = sh.exec("#{command_ruby(COMMAND_FILENAME_CREATE)} new -a always -D self -t time #{dir}", :check => true)
  result.strip!
end