bmc-daemon-lib 0.13.2 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c82b143ff8a357de485934538617e19a176535ed160cf608ccd652ded70abaee
4
- data.tar.gz: 46f2b9db709b3197195eadfbd68378407cd1212c8ad61e63ef0c3856d7059814
3
+ metadata.gz: a692d3958d9367cbf2e7484d7cdbb116f92d8b3e3912a2f9d6d1e897fa349dd3
4
+ data.tar.gz: 4674d842282a1b12c0e5ce0db796fddbd00149690e4cb0561a448fbc166c2e75
5
5
  SHA512:
6
- metadata.gz: 396b40feb073d614a22ffc7b3999981bb2539d28fe44494aa790b8c0428183fc3d73cb1d2c545553ad88bbf6d86cfa1cc13654c974d55b3eb61736c40d793772
7
- data.tar.gz: b5f46871abf578101a6bf51078811a9c432276b382c02e7fd623c0b5d674b4635622552be6c466172435d79bdd389d94067b6cf3b646f9d8d97a445eb68c34ba
6
+ metadata.gz: b2da920d6c05e41c46563391fdf756a01d223b6366e64a0b8d37f55de22c4ef489fb8a4fd21f445b3d7d4c5359dca8df69d84f223ac8a9716c871a74da9aac29
7
+ data.tar.gz: 0fec9399f9e943f54f48d7464aa420558ac15057f49f4a78481290b105b0497028b7686626679f021d2b364db27f25739c58756c53fdf9c092a5c3d824815380
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  # Project version
4
- spec.version = "0.13.2"
4
+ spec.version = "0.13.3"
5
5
 
6
6
  # Project description
7
7
  spec.name = "bmc-daemon-lib"
@@ -71,286 +71,292 @@ module BmcDaemonLib
71
71
  to_hash.to_yaml(indent: 4, useheader: true, useversion: false )
72
72
  end
73
73
 
74
- end
75
-
76
- # Direct access to any depth
77
- def self.at *path
78
- path.reduce(Conf) { |m, key| m && m[key.to_s] }
79
- end
80
-
81
- def self.logfile pipe
82
- # Build logfile from Conf
83
- logfile = self.logfile_path(pipe)
84
- return nil if logfile.nil?
85
-
86
- # Check that we'll be able to create logfiles
87
- if File.exists?(logfile)
88
- # File is there, is it writable ?
89
- unless File.writable?(logfile)
90
- log :conf, "logging [#{pipe}] disabled: file not writable [#{logfile}]"
91
- return nil
74
+ def dump_to_logs
75
+ self.log :conf, "configuration dump
76
+ dump.lines.each do |line|
77
+ self.log :conf, "| #{line.rstrip}"
92
78
  end
93
- else
94
- # No file here, can we create it ?
95
- logdir = File.dirname(logfile)
96
- unless File.writable?(logdir)
97
- log :conf, "logging [#{pipe}] disabled: directory not writable [#{logdir}]"
98
- return nil
79
+ end
80
+
81
+ # Direct access to any depth
82
+ def at *path
83
+ path.reduce(Conf) { |m, key| m && m[key.to_s] }
84
+ end
85
+
86
+ def logfile pipe
87
+ # Build logfile from Conf
88
+ logfile = self.logfile_path(pipe)
89
+ return nil if logfile.nil?
90
+
91
+ # Check that we'll be able to create logfiles
92
+ if ::File.exists?(logfile)
93
+ # File is there, is it writable ?
94
+ unless ::File.writable?(logfile)
95
+ log :conf, "logging [#{pipe}] disabled: file not writable [#{logfile}]"
96
+ return nil
97
+ end
98
+ else
99
+ # No file here, can we create it ?
100
+ logdir = ::File.dirname(logfile)
101
+ unless ::File.writable?(logdir)
102
+ log :conf, "logging [#{pipe}] disabled: directory not writable [#{logdir}]"
103
+ return nil
104
+ end
99
105
  end
106
+
107
+ # OK, return a clean file path
108
+ log :conf, "logging [#{pipe}] to [#{logfile}]"
109
+ return logfile
100
110
  end
101
111
 
102
- # OK, return a clean file path
103
- log :conf, "logging [#{pipe}] to [#{logfile}]"
104
- return logfile
105
- end
112
+ # Feature testers
113
+ def gem_installed? gemname
114
+ Gem::Specification.collect(&:name).include? gemname
115
+ end
116
+ def feature_newrelic?
117
+ return false unless gem_installed?('newrelic_rpm')
118
+ return false if self.at(:newrelic, :enabled) == false
119
+ return false if self.at(:newrelic, :disabled) == true
120
+ return self.at(:newrelic, :license) || false
121
+ end
122
+ def feature_rollbar?
123
+ return false unless gem_installed?('rollbar')
124
+ return false if self.at(:rollbar, :enabled) == false
125
+ return false if self.at(:rollbar, :disabled) == true
126
+ return self.at(:rollbar, :token) || false
127
+ end
106
128
 
107
- # Feature testers
108
- def self.gem_installed? gemname
109
- Gem::Specification.collect(&:name).include? gemname
110
- end
111
- def self.feature_newrelic?
112
- return false unless gem_installed?('newrelic_rpm')
113
- return false if self.at(:newrelic, :enabled) == false
114
- return false if self.at(:newrelic, :disabled) == true
115
- return self.at(:newrelic, :license) || false
116
- end
117
- def self.feature_rollbar?
118
- return false unless gem_installed?('rollbar')
119
- return false if self.at(:rollbar, :enabled) == false
120
- return false if self.at(:rollbar, :disabled) == true
121
- return self.at(:rollbar, :token) || false
122
- end
129
+ def feature? name
130
+ case name
131
+ when :newrelic
132
+ return feature_newrelic?
133
+ when :rollbar
134
+ return feature_rollbar?
135
+ end
136
+ return false
137
+ end
123
138
 
124
- def self.feature? name
125
- case name
126
- when :newrelic
127
- return feature_newrelic?
128
- when :rollbar
129
- return feature_rollbar?
139
+ # Generators
140
+ def app_libs
141
+ check_presence_of @app_name, @app_root
142
+
143
+ ::File.expand_path("lib/#{@app_name}/", @app_root)
130
144
  end
131
- return false
132
- end
133
145
 
134
- # Generators
135
- def self.app_libs
136
- check_presence_of @app_name, @app_root
146
+ def generate_user_agent
147
+ check_presence_of @app_name, @app_ver
137
148
 
138
- ::File.expand_path("lib/#{@app_name}/", @app_root)
139
- end
149
+ "#{@app_name}/#{@app_ver}"
150
+ end
140
151
 
141
- def self.generate_user_agent
142
- check_presence_of @app_name, @app_ver
152
+ def generate_process_name
153
+ check_presence_of @app_name, @app_env
143
154
 
144
- "#{@app_name}/#{@app_ver}"
145
- end
155
+ parts = [@app_name, @app_env]
156
+ parts << self[:port] if self[:port]
157
+ parts.join('-')
158
+ end
146
159
 
147
- def self.generate_process_name
148
- check_presence_of @app_name, @app_env
160
+ def generate_config_defaults
161
+ check_presence_of @app_root
162
+ "#{@app_root}/defaults.yml"
163
+ end
149
164
 
150
- parts = [@app_name, @app_env]
151
- parts << self[:port] if self[:port]
152
- parts.join('-')
153
- end
165
+ def generate_config_etc
166
+ check_presence_of @app_name
167
+ "/etc/#{@app_name}.yml"
168
+ end
154
169
 
155
- def self.generate_config_defaults
156
- check_presence_of @app_root
157
- "#{@app_root}/defaults.yml"
158
- end
170
+ def generate_pidfile
171
+ ::File.expand_path "#{self.generate_process_name}.pid", PIDFILE_DIR
172
+ end
159
173
 
160
- def self.generate_config_etc
161
- check_presence_of @app_name
162
- "/etc/#{@app_name}.yml"
163
- end
174
+ def generate_config_message
175
+ return unless self.generate_config_defaults && self.generate_config_etc
176
+ "A default configuration is available (#{self.generate_config_defaults}) and can be copied to the default location (#{self.generate_config_etc}): \n sudo cp #{self.generate_config_defaults} #{self.generate_config_etc}"
177
+ end
164
178
 
165
- def self.generate_pidfile
166
- ::File.expand_path "#{self.generate_process_name}.pid", PIDFILE_DIR
167
- end
179
+ # Plugins
180
+ def prepare_newrelic
181
+ # Disable if no config present
182
+ return unless self.feature?(:newrelic)
168
183
 
169
- def self.generate_config_message
170
- return unless self.generate_config_defaults && self.generate_config_etc
171
- "A default configuration is available (#{self.generate_config_defaults}) and can be copied to the default location (#{self.generate_config_etc}): \n sudo cp #{self.generate_config_defaults} #{self.generate_config_etc}"
172
- end
184
+ # Ok, let's start
185
+ log :conf, "prepare NewRelic"
186
+ conf = self[:newrelic]
173
187
 
174
- # Plugins
175
- def self.prepare_newrelic
176
- # Disable if no config present
177
- return unless self.feature?(:newrelic)
188
+ # Enable GC profiler
189
+ GC::Profiler.enable
178
190
 
179
- # Ok, let's start
180
- log :conf, "prepare NewRelic"
181
- conf = self[:newrelic]
191
+ # Build NewRelic app_name if not provided as-is
192
+ self.newrelic_init_app_name(conf)
182
193
 
183
- # Enable GC profiler
184
- GC::Profiler.enable
194
+ # Set env variables
195
+ ENV["NEW_RELIC_AGENT_ENABLED"] = "true"
196
+ ENV["NEW_RELIC_LOG"] = logfile_path(:newrelic)
197
+ ENV["NEW_RELIC_LICENSE_KEY"] = conf[:license].to_s
198
+ ENV["NEW_RELIC_APP_NAME"] = conf[:app_name].to_s
199
+ end
185
200
 
186
- # Build NewRelic app_name if not provided as-is
187
- self.newrelic_init_app_name(conf)
201
+ def prepare_rollbar
202
+ # Disable if no config present
203
+ unless self.feature?(:rollbar)
204
+ Rollbar.configure do |config|
205
+ config.enabled = false
206
+ end
207
+ return
208
+ end
188
209
 
189
- # Set env variables
190
- ENV["NEW_RELIC_AGENT_ENABLED"] = "true"
191
- ENV["NEW_RELIC_LOG"] = logfile_path(:newrelic)
192
- ENV["NEW_RELIC_LICENSE_KEY"] = conf[:license].to_s
193
- ENV["NEW_RELIC_APP_NAME"] = conf[:app_name].to_s
194
- end
210
+ # Ok, let's start
211
+ log :conf, "prepare Rollbar"
212
+ conf = self[:rollbar]
195
213
 
196
- def self.prepare_rollbar
197
- # Disable if no config present
198
- unless self.feature?(:rollbar)
214
+ # Configure
199
215
  Rollbar.configure do |config|
200
- config.enabled = false
216
+ config.enabled = true
217
+ config.access_token = conf[:token].to_s
218
+ config.code_version = @app_version
219
+ config.environment = @app_env
220
+ config.logger = LoggerPool.instance.get(:rollbar)
221
+ config.use_async = true
201
222
  end
202
- return
203
- end
204
223
 
205
- # Ok, let's start
206
- log :conf, "prepare Rollbar"
207
- conf = self[:rollbar]
208
-
209
- # Configure
210
- Rollbar.configure do |config|
211
- config.enabled = true
212
- config.access_token = conf[:token].to_s
213
- config.code_version = @app_version
214
- config.environment = @app_env
215
- config.logger = LoggerPool.instance.get(:rollbar)
216
- config.use_async = true
224
+ # Notify startup
225
+ Rollbar.info("[#{@app_ver}] #{@app_host}")
217
226
  end
218
227
 
219
- # Notify startup
220
- Rollbar.info("[#{@app_ver}] #{@app_host}")
221
- end
228
+ def reload
229
+ files=[]
222
230
 
223
- def self.log origin, message
224
- printf(
225
- "%s %-14s %s \n",
226
- Time.now.strftime("%Y-%m-%d %H:%M:%S"),
227
- origin,
228
- message
229
- )
230
- end
231
+ # Load defaults
232
+ add_config(files, self.generate_config_defaults)
231
233
 
232
- protected
234
+ # Load etc config
235
+ add_config(files, self.generate_config_etc)
233
236
 
234
- def self.init_from_gemspec
235
- # Check conditions
236
- check_presence_of @app_root
237
+ # Load app config
238
+ add_config(files, @app_config)
237
239
 
238
- # puts "Conf.init_from_gemspec"
239
- gemspec_path = "#{@app_root}/*.gemspec"
240
+ # Reload config
241
+ # puts "Conf.reload: loading files: #{files.inspect}"
242
+ log :conf, "reloading from files: #{files.inspect}"
243
+ load files: files, namespaces: { environment: @app_env }
240
244
 
241
- # Try to find any gemspec file
242
- matches = Dir[gemspec_path]
243
- fail ConfigGemspecMissing, "gemspec file not found: #{gemspec_path}" if matches.size < 1
244
- fail ConfigGemspecNotUnique, "gemspec file not found: #{gemspec_path}" if matches.size > 1
245
+ # Try to access any key to force parsing of the files
246
+ self[:test35547647654856865436346453754746588586799078079876543245678654324567865432]
245
247
 
246
- # Load Gemspec (just the only match)
247
- @spec = Gem::Specification::load(matches.first)
248
- fail ConfigGemspecInvalid, "gemspec not readable: #{gemspec_path}" unless @spec
249
-
250
- # Extract useful information from gemspec
251
- @app_name = @spec.name.to_s
252
- @app_ver = @spec.version.to_s
253
- fail ConfigMissingParameter, "gemspec: missing name" unless @app_name
254
- fail ConfigMissingParameter, "gemspec: missing version" unless @app_ver
248
+ rescue Psych::SyntaxError => e
249
+ fail ConfigParseError, e.message
250
+ rescue StandardError => e
251
+ fail ConfigOtherError, "#{e.message} \n #{e.backtrace.to_yaml}"
252
+ else
253
+ return to_hash
254
+ end
255
255
 
256
- return @spec
257
- end
256
+ def log origin, message
257
+ printf(
258
+ "%s %-14s %s \n",
259
+ Time.now.strftime("%Y-%m-%d %H:%M:%S"),
260
+ origin,
261
+ message
262
+ )
263
+ end
258
264
 
259
- def self.newrelic_init_app_name conf
260
- # Ignore if already set
261
- return if @app_name
265
+ protected
262
266
 
263
- # Check conditions
264
- check_presence_of @app_env
267
+ def init_from_gemspec
268
+ # Check conditions
269
+ check_presence_of @app_root
265
270
 
266
- # Stack all those parts
267
- stack = []
268
- stack << (conf[:prefix] || @app_name)
269
- stack << conf[:platform] if conf[:platform]
270
- stack << @app_env
271
- text = stack.join('-')
271
+ # puts "Conf.init_from_gemspec"
272
+ gemspec_path = "#{@app_root}/*.gemspec"
272
273
 
273
- # Return a composite appname
274
- conf[:app_name] = "#{text}; #{text}-#{@app_host}"
275
- end
274
+ # Try to find any gemspec file
275
+ matches = Dir[gemspec_path]
276
+ fail ConfigGemspecMissing, "gemspec file not found: #{gemspec_path}" if matches.size < 1
277
+ fail ConfigGemspecNotUnique, "gemspec file not found: #{gemspec_path}" if matches.size > 1
276
278
 
277
- def self.reload
278
- files=[]
279
+ # Load Gemspec (just the only match)
280
+ @spec = Gem::Specification::load(matches.first)
281
+ fail ConfigGemspecInvalid, "gemspec not readable: #{gemspec_path}" unless @spec
279
282
 
280
- # Load defaults
281
- add_config(files, self.generate_config_defaults)
283
+ # Extract useful information from gemspec
284
+ @app_name = @spec.name.to_s
285
+ @app_ver = @spec.version.to_s
286
+ fail ConfigMissingParameter, "gemspec: missing name" unless @app_name
287
+ fail ConfigMissingParameter, "gemspec: missing version" unless @app_ver
282
288
 
283
- # Load etc config
284
- add_config(files, self.generate_config_etc)
289
+ return @spec
290
+ end
285
291
 
286
- # Load app config
287
- add_config(files, @app_config)
292
+ def newrelic_init_app_name conf
293
+ # Ignore if already set
294
+ return if @app_name
288
295
 
289
- # Reload config
290
- # puts "Conf.reload: loading files: #{files.inspect}"
291
- log :conf, "reloading from files: #{files.inspect}"
292
- load files: files, namespaces: { environment: @app_env }
296
+ # Check conditions
297
+ check_presence_of @app_env
293
298
 
294
- # Try to access any key to force parsing of the files
295
- self[:test35547647654856865436346453754746588586799078079876543245678654324567865432]
299
+ # Stack all those parts
300
+ stack = []
301
+ stack << (conf[:prefix] || @app_name)
302
+ stack << conf[:platform] if conf[:platform]
303
+ stack << @app_env
304
+ text = stack.join('-')
296
305
 
297
- rescue Psych::SyntaxError => e
298
- fail ConfigParseError, e.message
299
- rescue StandardError => e
300
- fail ConfigOtherError, "#{e.message} \n #{e.backtrace.to_yaml}"
306
+ # Return a composite appname
307
+ conf[:app_name] = "#{text}; #{text}-#{@app_host}"
308
+ end
301
309
 
302
- else
303
- return to_hash
304
- end
310
+ def add_config files, path
311
+ # Should be not empty/nil
312
+ return unless path
305
313
 
306
- def self.add_config files, path
307
- # Should be not empty/nil
308
- return unless path
314
+ # Should be readable
315
+ return unless ::File.readable?(path)
309
316
 
310
- # Should be readable
311
- return unless File.readable?(path)
317
+ # Check if Chamber's behaviour may cause problems with hyphens
318
+ basename = ::File.basename(path)
319
+ if basename.include?'-'
320
+ log :conf, "WARNING: files with dashes may cause unexpected behaviour with Chamber (#{basename})"
321
+ end
312
322
 
313
- # Check if Chamber's behaviour may cause problems with hyphens
314
- basename = File.basename(path)
315
- if basename.include?'-'
316
- log :conf, "WARNING: files with dashes may cause unexpected behaviour with Chamber (#{basename})"
323
+ # Add it
324
+ files << ::File.expand_path(path)
317
325
  end
318
326
 
319
- # Add it
320
- files << File.expand_path(path)
321
- end
322
-
323
- def self.logfile_path pipe
324
- # Access configuration
325
- path = self.at :logs, :path
326
- specific = self.at :logs, pipe
327
- default = self.at :logs, :default
327
+ def logfile_path pipe
328
+ # Access configuration
329
+ path = self.at :logs, :path
330
+ specific = self.at :logs, pipe
331
+ default = self.at :logs, :default
328
332
 
329
- # Ignore if explicitely disabled
330
- return nil if specific == false
333
+ # Ignore if explicitely disabled
334
+ return nil if specific == false
331
335
 
332
- # Fallback on default path if not provided,
333
- specific ||= default
334
- specific ||= "default.log"
336
+ # Fallback on default path if not provided,
337
+ specific ||= default
338
+ specific ||= "default.log"
335
339
 
336
- # Build logfile_path
337
- File.expand_path specific.to_s, path.to_s
338
- end
340
+ # Build logfile_path
341
+ ::File.expand_path specific.to_s, path.to_s
342
+ end
339
343
 
340
- private
344
+ private
341
345
 
342
- # Check every argument for value presence
343
- def self.check_presence_of *args
344
- # puts "check_presence_of #{args.inspect}"
345
- args.each do |arg|
346
- # OK if it's not empty
347
- # puts "- [#{arg}]"
348
- next unless arg.to_s.empty?
346
+ # Check every argument for value presence
347
+ def check_presence_of *args
348
+ # puts "check_presence_of #{args.inspect}"
349
+ args.each do |arg|
350
+ # OK if it's not empty
351
+ # puts "- [#{arg}]"
352
+ next unless arg.to_s.empty?
349
353
 
350
- # Otherise, we just exit
351
- log :conf, "FAILED: object Conf has not been initialized correctly yet"
352
- exit 200
354
+ # Otherise, we just exit
355
+ log :conf, "FAILED: object Conf has not been initialized correctly yet"
356
+ exit 200
357
+ end
353
358
  end
359
+
354
360
  end
355
361
 
356
362
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmc-daemon-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno MEDICI