Class: DRbQS::SSHShell
- Inherits:
-
Object
- Object
- DRbQS::SSHShell
- Defined in:
- lib/drbqs/ssh/shell.rb
Overview
Requirements:
bash
nohup
Defined Under Namespace
Classes: GetInvalidExitStatus
Constant Summary collapse
- DEFAULT_RVM_SCRIPT =
'$HOME/.rvm/scripts/rvm'
- DEFAULT_OUTPUT_FILE =
'drbqs_nohup.log'
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #get_environment ⇒ Object
-
#initialize(dest, opts = {}) ⇒ SSHShell
constructor
:shell shell to use :dir base directory of ssh server :rvm version of ruby on rvm :rvm_init path of script to initialize rvm :output file to output of stdout and stderr.
- #start(*args) ⇒ Object
Constructor Details
#initialize(dest, opts = {}) ⇒ SSHShell
:shell shell to use :dir base directory of ssh server :rvm version of ruby on rvm :rvm_init path of script to initialize rvm :output file to output of stdout and stderr
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/drbqs/ssh/shell.rb', line 23 def initialize(dest, opts = {}) @user, @host, @port = split_destination(dest) if !(@host && @user) raise "Invalid destination of ssh server." end @shell = opts[:shell] || 'bash' @rvm = opts[:rvm] @rvm_init = opts[:rvm_init] if (@rvm || @rvm_init) && !(String === @rvm_init) @rvm_init = DEFAULT_RVM_SCRIPT end @nohup_output = opts[:output] || DEFAULT_OUTPUT_FILE @directory = opts[:dir] @out = $stdout @nice = opts[:nice] @nohup = opts[:nohup] end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
13 14 15 |
# File 'lib/drbqs/ssh/shell.rb', line 13 def directory @directory end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
13 14 15 |
# File 'lib/drbqs/ssh/shell.rb', line 13 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/drbqs/ssh/shell.rb', line 13 def port @port end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
13 14 15 |
# File 'lib/drbqs/ssh/shell.rb', line 13 def user @user end |
Instance Method Details
#get_environment ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/drbqs/ssh/shell.rb', line 110 def get_environment execute_command do |sh| ['echo "directory: " `pwd`', 'echo "files:"', 'ls', 'if which rvm > /dev/null; then rvm info; else ruby -v; fi'].each do |cmd| shell_exec(sh, cmd) end end end |
#start(*args) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/drbqs/ssh/shell.rb', line 121 def start(*args) cmd = args.join(' ') if @nice if Integer === @nice cmd = "nice -n #{@nice.to_s} " + cmd else cmd = "nice " + cmd end end execute_command do |sh| if @nohup pr, path = shell_exec_check(sh, "filename-create new -p middle -D parent -t time #{@nohup_output}") cmd = "nohup #{cmd} > #{path.strip} 2>&1 &" end shell_exec(sh, cmd) end end |