Top Level Namespace

Defined Under Namespace

Modules: ActiveSupport, Appsignal

Constant Summary collapse

EXT_PATH =
File.expand_path('..', __FILE__)
AGENT_CONFIG =
YAML.load(File.read(File.join(EXT_PATH, 'agent.yml')))
ARCH =
"#{Gem::Platform.local.cpu}-#{Gem::Platform.local.os}"
CA_CERT_PATH =
File.join(EXT_PATH, '../resources/cacert.pem')

Instance Method Summary collapse

Instance Method Details

#ext_path(path) ⇒ Object


15
16
17
# File 'ext/extconf.rb', line 15

def ext_path(path)
  File.join(EXT_PATH, path)
end

#installObject


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'ext/extconf.rb', line 30

def install
  logger.info "Installing appsignal agent #{Appsignal::VERSION} for Ruby #{RUBY_VERSION} on #{RUBY_PLATFORM}"

  if RUBY_PLATFORM =~ /java/
    installation_failed(
      "We do not support jRuby at the moment, email [email protected] if you want to join the beta"
    )
    return
  end

  unless AGENT_CONFIG['triples'].keys.include?(ARCH)
    installation_failed(
      "AppSignal currently does not support your system architecture (#{ARCH})." \
      "Please let us know at [email protected], we aim to support everything our customers run."
    )
    return
  end

  arch_config = AGENT_CONFIG['triples'][ARCH]

  unless File.exists?(ext_path('appsignal-agent')) &&
           File.exists?(ext_path('libappsignal.a')) &&
           File.exists?(ext_path('appsignal_extension.h'))
    logger.info "Downloading agent release from #{arch_config['download_url']}"

    archive = open(arch_config['download_url'], :ssl_ca_cert => CA_CERT_PATH)

    if Digest::SHA256.hexdigest(archive.read) == arch_config['checksum']
      logger.info 'Checksum of downloaded archive verified, extracting archive'
    else
      installation_failed(
        "Aborting installation, checksum of downloaded archive could not be verified: " \
        "Expected '#{arch_config['checksum']}', got '#{checksum}'."
      )
      return
    end

    Gem::Package::TarReader.new(Zlib::GzipReader.open(archive)) do |tar|
      tar.each do |entry|
        if entry.file?
          File.open(ext_path(entry.full_name), 'wb') do |f|
            f.write(entry.read)
          end
        end
      end
    end
    FileUtils.chmod(0755, ext_path('appsignal-agent'))
  end

  logger.info "Creating makefile"
  require 'mkmf'
  if !find_library('appsignal', 'appsignal_start', EXT_PATH)
    installation_failed 'Aborting installation, libappsignal not found'
  elsif !find_executable('appsignal-agent', EXT_PATH)
    installation_failed 'Aborting installation, appsignal-agent not found'
  elsif !find_header('appsignal_extension.h', EXT_PATH)
    installation_failed 'Aborting installation, appsignal_extension.h not found'
  else
    create_makefile 'appsignal_extension'
    logger.info 'Successfully installed appsignal extension'
  end
rescue => ex
  installation_failed "Exception while installing: #{ex}"
  ex.backtrace.each do |line|
    logger.error line
  end
end

#installation_failed(reason) ⇒ Object


23
24
25
26
27
28
# File 'ext/extconf.rb', line 23

def installation_failed(reason)
  logger.error "Installation failed: #{reason}"
  File.open(File.join(EXT_PATH, 'Makefile'), 'w') do |file|
      file.write "default:\nclean:\ninstall:"
  end
end

#loggerObject


19
20
21
# File 'ext/extconf.rb', line 19

def logger
  @logger ||= Logger.new(File.join(EXT_PATH, 'install.log'))
end