rest-ftp-daemon 0.302.3 → 0.304.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -3
- data/README.md +1 -1
- data/bin/rest-ftp-daemon +3 -3
- data/config.ru +1 -1
- data/defaults.yml +2 -2
- data/lib/rest-ftp-daemon/api/root.rb +10 -4
- data/lib/rest-ftp-daemon/api/status.rb +10 -0
- data/lib/rest-ftp-daemon/constants.rb +1 -4
- data/lib/rest-ftp-daemon/counters.rb +4 -2
- data/lib/rest-ftp-daemon/job.rb +11 -12
- data/lib/rest-ftp-daemon/job_queue.rb +10 -12
- data/lib/rest-ftp-daemon/launcher.rb +1 -0
- data/lib/rest-ftp-daemon/metrics.rb +10 -0
- data/lib/rest-ftp-daemon/notification.rb +5 -5
- data/lib/rest-ftp-daemon/paginate.rb +1 -0
- data/lib/rest-ftp-daemon/path.rb +2 -0
- data/lib/rest-ftp-daemon/remote.rb +5 -4
- data/lib/rest-ftp-daemon/remote_ftp.rb +3 -1
- data/lib/rest-ftp-daemon/remote_sftp.rb +4 -2
- data/lib/rest-ftp-daemon/views/dashboard_workers.haml +4 -1
- data/lib/rest-ftp-daemon/worker_pool.rb +6 -7
- data/lib/rest-ftp-daemon/workers/conchita.rb +8 -7
- data/lib/rest-ftp-daemon/workers/reporter.rb +24 -12
- data/lib/rest-ftp-daemon/workers/transfer.rb +8 -7
- data/lib/rest-ftp-daemon/workers/worker.rb +12 -0
- data/lib/rest-ftp-daemon.rb +10 -16
- data/lib/{rest-ftp-daemon → shared}/patch_array.rb +0 -0
- data/lib/{rest-ftp-daemon → shared}/patch_haml.rb +0 -2
- data/rest-ftp-daemon.gemspec +29 -28
- metadata +34 -24
- data/lib/rest-ftp-daemon/logger_pool.rb +0 -61
- data/lib/shared/conf.rb +0 -201
- data/lib/shared/logger_formatter.rb +0 -31
- data/lib/shared/logger_helper.rb +0 -78
- data/lib/shared/worker_base.rb +0 -112
data/lib/rest-ftp-daemon.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
1
|
# Global libs
|
3
2
|
require "rubygems"
|
3
|
+
require 'bmc-daemon-lib'
|
4
4
|
require "json"
|
5
5
|
require "haml"
|
6
6
|
require "uri"
|
@@ -10,32 +10,20 @@ require "thread"
|
|
10
10
|
require "newrelic_rpm"
|
11
11
|
|
12
12
|
|
13
|
-
# Shared libs
|
14
|
-
require_relative "shared/
|
15
|
-
require_relative "shared/
|
16
|
-
require_relative "shared/conf"
|
17
|
-
require_relative "shared/worker_base"
|
18
|
-
|
19
|
-
|
20
|
-
# HAML and Array monkey-patching
|
21
|
-
require_relative "rest-ftp-daemon/patch_array"
|
22
|
-
require_relative "rest-ftp-daemon/patch_haml"
|
13
|
+
# Shared libs / monkey-patching
|
14
|
+
require_relative "shared/patch_array"
|
15
|
+
require_relative "shared/patch_haml"
|
23
16
|
|
24
17
|
|
25
18
|
# Project's libs
|
26
19
|
require_relative "rest-ftp-daemon/constants"
|
27
20
|
require_relative "rest-ftp-daemon/exceptions"
|
28
21
|
require_relative "rest-ftp-daemon/helpers"
|
29
|
-
require_relative "rest-ftp-daemon/logger_pool"
|
30
22
|
require_relative "rest-ftp-daemon/metrics"
|
31
23
|
require_relative "rest-ftp-daemon/paginate"
|
32
24
|
require_relative "rest-ftp-daemon/uri"
|
33
25
|
require_relative "rest-ftp-daemon/job_queue"
|
34
26
|
require_relative "rest-ftp-daemon/counters"
|
35
|
-
require_relative "rest-ftp-daemon/worker_pool"
|
36
|
-
require_relative "rest-ftp-daemon/workers/conchita"
|
37
|
-
require_relative "rest-ftp-daemon/workers/reporter"
|
38
|
-
require_relative "rest-ftp-daemon/workers/transfer"
|
39
27
|
require_relative "rest-ftp-daemon/job"
|
40
28
|
require_relative "rest-ftp-daemon/notification"
|
41
29
|
|
@@ -44,6 +32,12 @@ require_relative "rest-ftp-daemon/remote"
|
|
44
32
|
require_relative "rest-ftp-daemon/remote_ftp"
|
45
33
|
require_relative "rest-ftp-daemon/remote_sftp"
|
46
34
|
|
35
|
+
require_relative "rest-ftp-daemon/worker_pool"
|
36
|
+
require_relative "rest-ftp-daemon/workers/worker"
|
37
|
+
require_relative "rest-ftp-daemon/workers/conchita"
|
38
|
+
require_relative "rest-ftp-daemon/workers/reporter"
|
39
|
+
require_relative "rest-ftp-daemon/workers/transfer"
|
40
|
+
|
47
41
|
require_relative "rest-ftp-daemon/api/job_presenter"
|
48
42
|
require_relative "rest-ftp-daemon/api/jobs"
|
49
43
|
require_relative "rest-ftp-daemon/api/dashboard"
|
File without changes
|
data/rest-ftp-daemon.gemspec
CHANGED
@@ -2,24 +2,24 @@
|
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
|
4
4
|
# Project version
|
5
|
-
spec.version
|
5
|
+
spec.version = "0.304.0"
|
6
6
|
|
7
7
|
# Project description
|
8
|
-
spec.name
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.description
|
12
|
-
spec.summary
|
13
|
-
spec.homepage
|
14
|
-
spec.licenses
|
15
|
-
spec.date
|
8
|
+
spec.name = "rest-ftp-daemon"
|
9
|
+
spec.authors = ["Bruno MEDICI"]
|
10
|
+
spec.email = "rest-ftp-daemon@bmconseil.com"
|
11
|
+
spec.description = "This is a pretty simple FTP client daemon, controlled through a RESTful API"
|
12
|
+
spec.summary = "RESTful FTP client daemon"
|
13
|
+
spec.homepage = "http://github.com/bmedici/rest-ftp-daemon"
|
14
|
+
spec.licenses = ["MIT"]
|
15
|
+
spec.date = Time.now.strftime("%Y-%m-%d")
|
16
16
|
|
17
17
|
|
18
18
|
# List files and executables
|
19
|
-
spec.files
|
20
|
-
spec.executables
|
21
|
-
spec.require_paths
|
22
|
-
spec.required_ruby_version
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject{ |f| f == "dashboard.png"}
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
spec.required_ruby_version = ">= 2.2"
|
23
23
|
|
24
24
|
|
25
25
|
# Development dependencies
|
@@ -28,21 +28,22 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "rspec"
|
29
29
|
spec.add_development_dependency "rubocop", "~> 0.32.0"
|
30
30
|
spec.add_development_dependency "pry"
|
31
|
+
spec.add_development_dependency "http"
|
31
32
|
|
32
33
|
# Runtime dependencies
|
33
|
-
spec.add_runtime_dependency
|
34
|
-
spec.add_runtime_dependency
|
35
|
-
spec.add_runtime_dependency "
|
36
|
-
spec.add_runtime_dependency
|
37
|
-
spec.add_runtime_dependency
|
38
|
-
spec.add_runtime_dependency
|
39
|
-
spec.add_runtime_dependency
|
40
|
-
spec.add_runtime_dependency
|
41
|
-
spec.add_runtime_dependency
|
42
|
-
spec.add_runtime_dependency
|
43
|
-
spec.add_runtime_dependency
|
44
|
-
spec.add_runtime_dependency
|
45
|
-
spec.add_runtime_dependency
|
46
|
-
spec.add_runtime_dependency
|
47
|
-
spec.add_runtime_dependency
|
34
|
+
spec.add_runtime_dependency "bmc-daemon-lib", "~> 0.2"
|
35
|
+
spec.add_runtime_dependency "json", "~> 1.8"
|
36
|
+
spec.add_runtime_dependency "thin", "~> 1.7"
|
37
|
+
spec.add_runtime_dependency "grape"
|
38
|
+
spec.add_runtime_dependency "grape-entity"
|
39
|
+
spec.add_runtime_dependency "settingslogic"
|
40
|
+
spec.add_runtime_dependency "rest-client", "~> 1.8"
|
41
|
+
spec.add_runtime_dependency "api-auth"
|
42
|
+
spec.add_runtime_dependency "haml"
|
43
|
+
spec.add_runtime_dependency "net-sftp"
|
44
|
+
spec.add_runtime_dependency "double-bag-ftps"
|
45
|
+
spec.add_runtime_dependency "facter"
|
46
|
+
spec.add_runtime_dependency "sys-cpu"
|
47
|
+
spec.add_runtime_dependency "get_process_mem"
|
48
|
+
spec.add_runtime_dependency "newrelic_rpm"
|
48
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-ftp-daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.304.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno MEDICI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,49 +81,63 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: http
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bmc-daemon-lib
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
103
|
+
version: '0.2'
|
90
104
|
type: :runtime
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
110
|
+
version: '0.2'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: json
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '1.
|
117
|
+
version: '1.8'
|
104
118
|
type: :runtime
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: '1.
|
124
|
+
version: '1.8'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
126
|
+
name: thin
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
|
-
- - "
|
129
|
+
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
131
|
+
version: '1.7'
|
118
132
|
type: :runtime
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
|
-
- - "
|
136
|
+
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
138
|
+
version: '1.7'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
|
-
name: grape
|
140
|
+
name: grape
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - ">="
|
@@ -137,7 +151,7 @@ dependencies:
|
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
154
|
+
name: grape-entity
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
157
|
- - ">="
|
@@ -151,7 +165,7 @@ dependencies:
|
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '0'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
168
|
+
name: settingslogic
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
156
170
|
requirements:
|
157
171
|
- - ">="
|
@@ -325,12 +339,9 @@ files:
|
|
325
339
|
- lib/rest-ftp-daemon/job.rb
|
326
340
|
- lib/rest-ftp-daemon/job_queue.rb
|
327
341
|
- lib/rest-ftp-daemon/launcher.rb
|
328
|
-
- lib/rest-ftp-daemon/logger_pool.rb
|
329
342
|
- lib/rest-ftp-daemon/metrics.rb
|
330
343
|
- lib/rest-ftp-daemon/notification.rb
|
331
344
|
- lib/rest-ftp-daemon/paginate.rb
|
332
|
-
- lib/rest-ftp-daemon/patch_array.rb
|
333
|
-
- lib/rest-ftp-daemon/patch_haml.rb
|
334
345
|
- lib/rest-ftp-daemon/path.rb
|
335
346
|
- lib/rest-ftp-daemon/remote.rb
|
336
347
|
- lib/rest-ftp-daemon/remote_ftp.rb
|
@@ -351,10 +362,9 @@ files:
|
|
351
362
|
- lib/rest-ftp-daemon/workers/conchita.rb
|
352
363
|
- lib/rest-ftp-daemon/workers/reporter.rb
|
353
364
|
- lib/rest-ftp-daemon/workers/transfer.rb
|
354
|
-
- lib/
|
355
|
-
- lib/shared/
|
356
|
-
- lib/shared/
|
357
|
-
- lib/shared/worker_base.rb
|
365
|
+
- lib/rest-ftp-daemon/workers/worker.rb
|
366
|
+
- lib/shared/patch_array.rb
|
367
|
+
- lib/shared/patch_haml.rb
|
358
368
|
- rest-ftp-daemon.gemspec
|
359
369
|
- spec/rest-ftp-daemon/features/dashboard_spec.rb
|
360
370
|
- spec/rest-ftp-daemon/features/debug_spec.rb
|
@@ -374,7 +384,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
374
384
|
requirements:
|
375
385
|
- - ">="
|
376
386
|
- !ruby/object:Gem::Version
|
377
|
-
version: 2.2
|
387
|
+
version: '2.2'
|
378
388
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
379
389
|
requirements:
|
380
390
|
- - ">="
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require "logger"
|
2
|
-
require "singleton"
|
3
|
-
|
4
|
-
# Logger interface class to access logger though symbolic names
|
5
|
-
module RestFtpDaemon
|
6
|
-
class LoggerPool
|
7
|
-
include Singleton
|
8
|
-
|
9
|
-
def get pipe
|
10
|
-
@loggers ||= {}
|
11
|
-
@loggers[pipe] ||= create(pipe)
|
12
|
-
end
|
13
|
-
|
14
|
-
def create pipe
|
15
|
-
# Compute logfile or STDERR, and declare what we're doing
|
16
|
-
filename = logfile(pipe)
|
17
|
-
|
18
|
-
# Create the logger and return it
|
19
|
-
logger = Logger.new(filename, LOG_ROTATION) #, 10, 1024000)
|
20
|
-
logger.progname = pipe.to_s.downcase
|
21
|
-
logger.formatter = Shared::LoggerFormatter
|
22
|
-
|
23
|
-
# Finally return this logger
|
24
|
-
logger
|
25
|
-
|
26
|
-
rescue Errno::EACCES
|
27
|
-
puts "LoggerPool [#{pipe}] failed: access error"
|
28
|
-
end
|
29
|
-
|
30
|
-
protected
|
31
|
-
|
32
|
-
def logfile pipe
|
33
|
-
# Disabled if no valid config
|
34
|
-
return nil unless Conf[:logs].is_a?(Hash)
|
35
|
-
|
36
|
-
# Compute logfile and check if we can write there
|
37
|
-
logfile = File.expand_path(Conf[:logs][pipe].to_s, Conf[:logs][:path].to_s)
|
38
|
-
|
39
|
-
# Check that we'll be able to create logfiles
|
40
|
-
if File.exists?(logfile)
|
41
|
-
# File is there, is it writable ?
|
42
|
-
unless File.writable?(logfile)
|
43
|
-
puts "LoggerPool [#{pipe}] disabled: file not writable [#{logfile}]"
|
44
|
-
return nil
|
45
|
-
end
|
46
|
-
else
|
47
|
-
# No file here, can we create it ?
|
48
|
-
logdir = File.dirname(logfile)
|
49
|
-
unless File.writable?(logdir)
|
50
|
-
puts "LoggerPool [#{pipe}] disabled: directory not writable [#{logdir}]"
|
51
|
-
return nil
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# OK, return a clean file path
|
56
|
-
puts "LoggerPool [#{pipe}] logging to [#{logfile}]"
|
57
|
-
return logfile
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
data/lib/shared/conf.rb
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
# FIXME: files named with hyphens will not be found by Chamber for now
|
2
|
-
require "chamber"
|
3
|
-
|
4
|
-
module Shared
|
5
|
-
class ConfigMissingParameter < StandardError; end
|
6
|
-
class ConfigOtherError < StandardError; end
|
7
|
-
class ConfigParseError < StandardError; end
|
8
|
-
class ConfigMultipleGemspec < StandardError; end
|
9
|
-
class ConfigMissingGemspec < StandardError; end
|
10
|
-
|
11
|
-
class Conf
|
12
|
-
extend Chamber
|
13
|
-
PIDFILE_DIR = "/tmp/"
|
14
|
-
|
15
|
-
class << self
|
16
|
-
attr_accessor :app_env
|
17
|
-
attr_reader :app_root
|
18
|
-
attr_reader :app_libs
|
19
|
-
attr_reader :app_name
|
20
|
-
attr_reader :app_ver
|
21
|
-
attr_reader :app_started
|
22
|
-
attr_reader :app_spec
|
23
|
-
attr_reader :files
|
24
|
-
attr_reader :host
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.init app_root
|
28
|
-
# Permanent flags
|
29
|
-
@initialized = true
|
30
|
-
@app_started = Time.now
|
31
|
-
|
32
|
-
# Default values
|
33
|
-
@files ||= []
|
34
|
-
@app_name ||= "app_name"
|
35
|
-
@app_env ||= "production"
|
36
|
-
@host ||= `hostname`.to_s.chomp.split(".").first
|
37
|
-
|
38
|
-
# Store and clean app_root
|
39
|
-
@app_root = File.expand_path(app_root)
|
40
|
-
|
41
|
-
# Try to find any gemspec file
|
42
|
-
matches = Dir["#{@app_root}/*.gemspec"]
|
43
|
-
fail ConfigMissingGemspec, "gemspec file not found: #{gemspec_path}" if matches.size < 1
|
44
|
-
fail ConfigMultipleGemspec, "gemspec file not found: #{gemspec_path}" if matches.size > 1
|
45
|
-
|
46
|
-
# Load Gemspec (just the only match)
|
47
|
-
@spec = Gem::Specification::load(matches.first)
|
48
|
-
@app_name = @spec.name
|
49
|
-
@app_ver = @spec.version
|
50
|
-
fail ConfigMissingParameter, "gemspec: missing name" unless @app_name
|
51
|
-
fail ConfigMissingParameter, "gemspec: missing version" unless @app_ver
|
52
|
-
|
53
|
-
# Now we know app_name, initalize app_libs
|
54
|
-
@app_libs = File.expand_path("lib/#{@app_name}/", @app_root)
|
55
|
-
|
56
|
-
# Add other config files
|
57
|
-
#add_default_config
|
58
|
-
add_config generate(:config_defaults)
|
59
|
-
add_config generate(:config_etc)
|
60
|
-
|
61
|
-
# Return something
|
62
|
-
return @app_name
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.prepare args = {}
|
66
|
-
ensure_init
|
67
|
-
|
68
|
-
# Add extra config file and load them all
|
69
|
-
add_config args[:config]
|
70
|
-
reload!
|
71
|
-
|
72
|
-
# Set Rack env
|
73
|
-
ENV["RACK_ENV"] = @app_env.to_s
|
74
|
-
|
75
|
-
# Set up encodings
|
76
|
-
Encoding.default_internal = "utf-8"
|
77
|
-
Encoding.default_external = "utf-8"
|
78
|
-
|
79
|
-
# Init New Relic
|
80
|
-
newrelic_logfile = File.expand_path(Conf[:logs][:newrelic].to_s, Conf[:logs][:path].to_s)
|
81
|
-
prepare_newrelic self[:newrelic], newrelic_logfile
|
82
|
-
|
83
|
-
# Try to access any key to force parsing of the files
|
84
|
-
self[:dummy]
|
85
|
-
|
86
|
-
rescue Psych::SyntaxError => e
|
87
|
-
fail ConfigParseError, e.message
|
88
|
-
rescue StandardError => e
|
89
|
-
fail ConfigOtherError, "#{e.message} \n #{e.backtrace.to_yaml}"
|
90
|
-
end
|
91
|
-
|
92
|
-
# Reload files
|
93
|
-
def self.reload!
|
94
|
-
ensure_init
|
95
|
-
load_files
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.dump
|
99
|
-
ensure_init
|
100
|
-
to_hash.to_yaml(indent: 4, useheader: true, useversion: false )
|
101
|
-
end
|
102
|
-
|
103
|
-
# Direct access to any depth
|
104
|
-
def self.at *path
|
105
|
-
ensure_init
|
106
|
-
path.reduce(Conf) { |m, key| m && m[key.to_s] }
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.newrelic_enabled?
|
110
|
-
ensure_init
|
111
|
-
self[:newrelic] && self[:newrelic][:licence]
|
112
|
-
end
|
113
|
-
|
114
|
-
# Defaults generators
|
115
|
-
def self.generate what
|
116
|
-
ensure_init
|
117
|
-
return case what
|
118
|
-
|
119
|
-
when :user_agent
|
120
|
-
"#{@app_name}/#{@app_ver}" if @app_name && @app_ver
|
121
|
-
|
122
|
-
when :config_defaults
|
123
|
-
"#{@app_root}/defaults.yml" if @app_root
|
124
|
-
|
125
|
-
when :config_etc
|
126
|
-
"/etc/#{@app_name}.yml" if @app_name
|
127
|
-
|
128
|
-
when :process_name
|
129
|
-
parts = [@app_name, @app_env]
|
130
|
-
parts << self[:port] if self[:port]
|
131
|
-
parts.join('-')
|
132
|
-
|
133
|
-
when :pidfile
|
134
|
-
process_name = self.generate(:process_name)
|
135
|
-
File.expand_path "#{process_name}.pid", PIDFILE_DIR
|
136
|
-
|
137
|
-
when :config_message
|
138
|
-
config_defaults = self.generate(:config_defaults)
|
139
|
-
config_etc = self.generate(:config_etc)
|
140
|
-
|
141
|
-
"A default configuration is available (#{config_defaults}) and can be copied to the default location (#{config_etc}): \n sudo cp #{config_defaults} #{config_etc}"
|
142
|
-
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
|
-
protected
|
148
|
-
|
149
|
-
def self.load_files
|
150
|
-
load files: @files, namespaces: { environment: @app_env }
|
151
|
-
end
|
152
|
-
|
153
|
-
def self.add_config path
|
154
|
-
@files << File.expand_path(path) if path && File.readable?(path)
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.prepare_newrelic section, logfile
|
158
|
-
# Disable NewRelic if no config present
|
159
|
-
unless self.newrelic_enabled?
|
160
|
-
ENV["NEWRELIC_AGENT_ENABLED"] = "false"
|
161
|
-
return
|
162
|
-
end
|
163
|
-
|
164
|
-
# Enable GC profiler
|
165
|
-
GC::Profiler.enable
|
166
|
-
|
167
|
-
# Enable module
|
168
|
-
ENV["NEWRELIC_AGENT_ENABLED"] = "true"
|
169
|
-
ENV["NEW_RELIC_MONITOR_MODE"] = "true"
|
170
|
-
|
171
|
-
# License
|
172
|
-
ENV["NEW_RELIC_LICENSE_KEY"] = section[:licence].to_s
|
173
|
-
|
174
|
-
# Build NewRelic app_name if not provided as-is
|
175
|
-
if section[:app_name]
|
176
|
-
ENV["NEW_RELIC_APP_NAME"] = section[:app_name].to_s
|
177
|
-
else
|
178
|
-
stack = []
|
179
|
-
stack << (section[:prefix] || @app_name)
|
180
|
-
stack << section[:platform] if section[:platform]
|
181
|
-
stack << @app_env
|
182
|
-
text = stack.join('-')
|
183
|
-
ENV["NEW_RELIC_APP_NAME"] = "#{text}-#{host};#{text}"
|
184
|
-
end
|
185
|
-
|
186
|
-
# Logfile
|
187
|
-
ENV["NEW_RELIC_LOG"] = logfile.to_s if logfile
|
188
|
-
end
|
189
|
-
|
190
|
-
private
|
191
|
-
|
192
|
-
def self.ensure_init
|
193
|
-
# Skip is already done
|
194
|
-
return if @initialized
|
195
|
-
|
196
|
-
# Go through init if not already done
|
197
|
-
self.init
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Shared
|
2
|
-
class LoggerFormatter
|
3
|
-
|
4
|
-
def self.call severity, datetime, progname, payload
|
5
|
-
# Build common values
|
6
|
-
timestamp = datetime.strftime(LOG_HEADER_TIME)
|
7
|
-
|
8
|
-
# Build header
|
9
|
-
header = sprintf LOG_HEADER_FORMAT,
|
10
|
-
timestamp,
|
11
|
-
Process.pid,
|
12
|
-
severity,
|
13
|
-
progname
|
14
|
-
|
15
|
-
# If we have a bunch of lines, prefix them and send them together
|
16
|
-
return payload.map do |line|
|
17
|
-
"#{header}#{trimmed(line)}\n"
|
18
|
-
end.join if payload.is_a?(Array)
|
19
|
-
|
20
|
-
# Otherwise, just prefix the only line
|
21
|
-
return "#{header}#{trimmed(payload)}\n"
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
|
26
|
-
def self.trimmed line
|
27
|
-
line.to_s.rstrip[0..LOG_MESSAGE_TRIM].force_encoding(Encoding::UTF_8)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
data/lib/shared/logger_helper.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require "logger"
|
2
|
-
|
3
|
-
module Shared
|
4
|
-
module LoggerHelper
|
5
|
-
|
6
|
-
protected
|
7
|
-
|
8
|
-
def log_info message, details = nil
|
9
|
-
build_messages Logger::INFO, message, details
|
10
|
-
end
|
11
|
-
|
12
|
-
def log_error message, details = nil
|
13
|
-
build_messages Logger::ERROR, message, details
|
14
|
-
end
|
15
|
-
|
16
|
-
def log_debug message, details = nil
|
17
|
-
build_messages Logger::DEBUG, message, details
|
18
|
-
end
|
19
|
-
|
20
|
-
alias info log_info
|
21
|
-
alias error log_error
|
22
|
-
alias debug log_debug
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
# Builds prefix if LOG_PREFIX_FORMAT defined and caller has log_prefix method to provide values
|
27
|
-
def build_prefix
|
28
|
-
# Skip if no values from user class
|
29
|
-
return unless respond_to?(:log_prefix, true)
|
30
|
-
values = log_prefix
|
31
|
-
|
32
|
-
# Skip if no format defined
|
33
|
-
return unless defined?('LOG_PREFIX_FORMAT')
|
34
|
-
return unless LOG_PREFIX_FORMAT.is_a? String
|
35
|
-
|
36
|
-
# Build prefix string
|
37
|
-
LOG_PREFIX_FORMAT % values.map(&:to_s)
|
38
|
-
end
|
39
|
-
|
40
|
-
def build_messages severity, message, details = nil
|
41
|
-
messages = []
|
42
|
-
# messages << "/---------------------------------------"
|
43
|
-
# messages << "severity: #{severity}"
|
44
|
-
# messages << "message: #{message.class}"
|
45
|
-
# messages << "details: #{details.class} #{details.inspect}"
|
46
|
-
# messages << "ARRAY(#{details.count})" if details.is_a? Array
|
47
|
-
# messages << "HASH(#{details.count})" if details.is_a? Hash
|
48
|
-
|
49
|
-
prefix = build_prefix
|
50
|
-
|
51
|
-
# Add main message
|
52
|
-
messages << sprintf(LOG_MESSAGE_TEXT, prefix, message) if message
|
53
|
-
|
54
|
-
# Add details from array
|
55
|
-
details.each do |line|
|
56
|
-
messages << sprintf(LOG_MESSAGE_ARRAY, prefix, line)
|
57
|
-
end if details.is_a? Array
|
58
|
-
|
59
|
-
# Add details from hash
|
60
|
-
details.each do |key, value|
|
61
|
-
messages << sprintf(LOG_MESSAGE_HASH, prefix, key, value)
|
62
|
-
end if details.is_a? Hash
|
63
|
-
|
64
|
-
# Return all that stuff
|
65
|
-
# messages << "\\---------------------------------------"
|
66
|
-
logger.add severity, messages
|
67
|
-
end
|
68
|
-
|
69
|
-
# def debug_lines lines, prefix = ''
|
70
|
-
# if lines.is_a? Array
|
71
|
-
# logger.debug lines.map{ |line| sprintf(LOG_MESSAGE_ARRAY, prefix, line) }
|
72
|
-
# elsif lines.is_a? Hash
|
73
|
-
# logger.debug lines.map{ |key, value| sprintf(LOG_MESSAGE_HASH, prefix, key, value) }
|
74
|
-
# end
|
75
|
-
# end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|