Class: DRbQS::Manage::SSHExecute

Inherits:
Object
  • Object
show all
Defined in:
lib/drbqs/manage/ssh_execute.rb

Constant Summary collapse

COMMAND_NICE =
"nice"
COMMAND_DRBQS_SERVER =
"drbqs-server"
COMMAND_DRBQS_NODE =
"drbqs-node"
COMMAND_FILENAME_CREATE =
"filename-create"

Instance Method Summary collapse

Constructor Details

#initialize(dest, opts = {}) ⇒ SSHExecute

Returns a new instance of SSHExecute.

Parameters:

  • dest (String)

    Destination name

  • opts (Hash) (defaults to: {})

    Option hash

Options Hash (opts):

  • :bundler (boolean)

    Use bundler to execute commands: filename-create, drbqs-server, and drbqs-node

  • :shell (String)

    Same as options DRbQS::Manage::SSHShell

  • :keys (String)

    Same as options DRbQS::Manage::SSHShell

  • :io (IO)

    Same as options DRbQS::Manage::SSHShell

  • :directory (String)

    Same as options DRbQS::Manage::SSHShell

  • :rvm (String)

    Same as options DRbQS::Manage::SSHShell

  • :rvm_init (String)

    Same as options DRbQS::Manage::SSHShell

  • :env (Hash)

    Same as options DRbQS::Manage::SSHShell



21
22
23
24
25
26
27
28
# 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

Instance Method Details

#command(command) ⇒ Object



30
31
32
# File 'lib/drbqs/manage/ssh_execute.rb', line 30

def command(command)
  @ssh_shell.execute_all(command)
end

#get_environmentObject



34
35
36
# File 'lib/drbqs/manage/ssh_execute.rb', line 34

def get_environment
  @ssh_shell.get_environment
end

#node(cmd_options, opts = {}) ⇒ Object

Add options --daemon and --log-prefix.



79
80
81
82
83
84
85
86
87
88
89
# 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 = {}) ⇒ Object

Add options --daemon and --log-file.



65
66
67
68
69
70
71
72
73
74
75
76
# 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