Class: Larrow::Runner::Service::Executor
- Inherits:
-
Object
- Object
- Larrow::Runner::Service::Executor
- Defined in:
- lib/larrow/runner/service/executor.rb
Instance Attribute Summary collapse
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #connection ⇒ Object
- #execute(cmd, base_dir: nil, verbose: nil) ⇒ Object
-
#initialize(ip, user, port, password) ⇒ Executor
constructor
A new instance of Executor.
- #scp(local_file_path, remote_file_path) ⇒ Object
Constructor Details
#initialize(ip, user, port, password) ⇒ Executor
Returns a new instance of Executor.
9 10 11 12 13 14 15 16 |
# File 'lib/larrow/runner/service/executor.rb', line 9 def initialize ip, user, port, password self.ip = ip self.user = user self.port = port self.password = password @canceling = nil @dlogger = RunLogger #::Logger.new "#{ip}_cmd.log" end |
Instance Attribute Details
#ip ⇒ Object
Returns the value of attribute ip.
8 9 10 |
# File 'lib/larrow/runner/service/executor.rb', line 8 def ip @ip end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/larrow/runner/service/executor.rb', line 8 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/larrow/runner/service/executor.rb', line 8 def port @port end |
#user ⇒ Object
Returns the value of attribute user.
8 9 10 |
# File 'lib/larrow/runner/service/executor.rb', line 8 def user @user end |
Instance Method Details
#connection ⇒ Object
50 51 52 |
# File 'lib/larrow/runner/service/executor.rb', line 50 def connection @connection ||= Net::SSH.start(ip,user) end |
#execute(cmd, base_dir: nil, verbose: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/larrow/runner/service/executor.rb', line 18 def execute cmd, base_dir:nil,verbose:nil connection.open_channel do |ch| RunLogger.level(1).detail "# #{cmd}" cmd = "cd #{base_dir}; #{cmd}" unless base_dir.nil? errmsg = '' ch.exec cmd do |ch,success| if verbose ch.on_data{ |c, data| yield data } ch.on_extended_data{ |c, type, data| yield data } else ch.on_extended_data{ |c, type, data| errmsg << data } end ch.on_request('exit-status') do |c,data| status = data.read_long if status != 0 fail ExecutionError,{cmd:cmd, errmsg: errmsg, status: status} end end end end trap("INT") { @canceling = true } connection.loop(0.1) do not (@canceling || connection.channels.empty?) end end |
#scp(local_file_path, remote_file_path) ⇒ Object
46 47 48 |
# File 'lib/larrow/runner/service/executor.rb', line 46 def scp local_file_path, remote_file_path raise 'not completed.' end |