Class: Aspera::Products::Transferd

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/products/transferd.rb

Constant Summary collapse

APP_NAME =
'IBM Aspera Transfer Daemon'
V1_DAEMON_NAME =
'asperatransferd'
V2_DAEMON_NAME =

from 1.1.5

'transferd'
RUNTIME_FOLDERS =

folders to extract from SDK archive

%w[bin lib sbin aspera].freeze
SERVICE_CONFIG_FILE =

Configuration file of the service installed by transferd service install, also the default of the daemon

'/etc/transferd/transferd.json'
PORT_FILE_PATTERN =

Files <name>.<port>.optport where the daemon started with port zero writes its port, in its runtime_dir (from 1.1.7)

'*.optport'

Class Method Summary collapse

Class Method Details

.daemon_port_from_file(runtime_dir) ⇒ Integer?

Port of a daemon started locally with port zero, from the file it writes in its runtime_dir once it listens (from 1.1.7)

Parameters:

  • runtime_dir (String) —

    Folder runtime_dir of the daemon, used by this daemon only

Returns:

  • (Integer, nil) —

    Port of the file, nil: no file (version before 1.1.7, or not listening yet), or file being written (empty)

Raises:

  • (AssertError) —

    The file has no port, or there are several: retrying does not help



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/aspera/products/transferd.rb', line 54

def daemon_port_from_file(runtime_dir)
  # `base`: the path of the folder is not a pattern
  files = Dir.glob(PORT_FILE_PATTERN, base: runtime_dir).map { |name| File.join(runtime_dir, name) }
  return if files.empty?
  Aspera.assert(files.length.eql?(1)) { "Several port files in #{runtime_dir}: #{files.join(', ')}" }
  # The file is created, then written
  content = File.read(files.first)
  return if content.empty?
  Aspera.assert(content.match?(/\A[0-9]+\z/)) { "No port in file #{files.first}" }
  Log.log.debug { "Got port #{content} from #{files.first}" }
  return content.to_i
end

.daemon_port_from_log(log_file) ⇒ Integer?

Port of a daemon started locally with port zero, from its log: transferd before 1.1.7 writes it only there (see daemon_port_from_file)

Parameters:

  • log_file (String) —

    Log file (standard output) of a daemon started locally

Returns:

  • (Integer, nil) —

    Port of the last line of the API server, nil: not listening yet



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/aspera/products/transferd.rb', line 70

def daemon_port_from_log(log_file)
  result = nil
  # if port is zero, a dynamic port was created, get it
  File.open(log_file, 'r') do |file|
    file.each_line do |line|
      # Well, it's tricky to depend on log
      if (m = line.match(/Info: API Server: Listening on ([^:]+):(\d+) /))
        result = m[2].to_i
        # no "break" , need to read last matching log line
      end
    end
  end
  Log.log.debug { "Got port #{result} from log" } unless result.nil?
  return result
end

.locations ⇒ Object

standard folder locations



24
25
26
27
28
29
# File 'lib/aspera/products/transferd.rb', line 24

def locations
  [{
    app_root: sdk_directory,
    sub_bin:  ''
  }].map { |i| i.merge({expected: APP_NAME}) }
end

.sdk_directory ⇒ String

Returns the path to folder where SDK is or should be installed.

Returns:

  • (String) —

    the path to folder where SDK is or should be installed



39
40
41
42
# File 'lib/aspera/products/transferd.rb', line 39

def sdk_directory
  Aspera.assert(!@sdk_dir.nil?, 'SDK path was not initialized')
  @sdk_dir
end

.sdk_directory=(folder) ⇒ Object

location of SDK files



32
33
34
35
36
# File 'lib/aspera/products/transferd.rb', line 32

def sdk_directory=(folder)
  Log.log.debug { "sdk_directory=#{folder}" }
  @sdk_dir = folder
  sdk_directory
end

.transferd_path ⇒ Object



44
45
46
47
48
# File 'lib/aspera/products/transferd.rb', line 44

def transferd_path
  v1_path = File.join(sdk_directory, Environment.instance.exe_file(V1_DAEMON_NAME))
  return v1_path if File.exist?(v1_path)
  return File.join(sdk_directory, Environment.instance.exe_file(V2_DAEMON_NAME))
end