Sha256: 89ca67669b77624d7ba77bebc3bf7749a74a1e5be24841404bb577794f4caae6
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 KB
Contents
require 'net/ssh' require 'net/scp' module Larrow module Runner module Service class Executor attr_accessor :ip, :user, :port, :password 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 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 def scp local_file_path, remote_file_path raise 'not completed.' end def connection @connection ||= Net::SSH.start(ip,user) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
larrow-runner-0.0.3 | lib/larrow/runner/service/executor.rb |