pushyd 0.4.2 → 0.5.0

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
  SHA1:
3
- metadata.gz: a7a636a06b2c41f7a69593b7a29b3bbac5d4686f
4
- data.tar.gz: eb4120ba4105fcfba107739e43c0ea77f09492a6
3
+ metadata.gz: 2afb6ffc0b508f3e4f2a04bd947ec1a9e52833d1
4
+ data.tar.gz: 000db1acc65e2be1a87e0351b4aba6578aa7ac55
5
5
  SHA512:
6
- metadata.gz: 88b640673acf8851e00ecd5b1d67ae58d6725e451d9eaee5d16de85b7ba59836ce6eb147ff98dd4f06e38cae1a38f10adc26e545ba686379d50921225c542844
7
- data.tar.gz: b448ff79dc864883b158bfd49a257a15d8850090c18570e04014bc713efab8138232a534561ac2ccade53b47d42112c6e91347ed77144ab8b5d0c5f4d0e41d10
6
+ metadata.gz: 1efc1420e8d39d6df4a375239b9400cc9b868752cf9dc6549f75d0041607bcf25e65c251ea888a2adb8a35b35dfbedae182a6a1ac160fefae655bc0f6b8348a2
7
+ data.tar.gz: f5d231791ae1526e7e852c1f13c74457446961aa2d7610e62fa5273d797bfca52129a6d7fdc6b91c45bfb90a2f8b8c4e1723ae9f0be4b4ef510714e59faf9a06
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pushyd (0.4.2)
4
+ pushyd (0.5.0)
5
5
  bunny (~> 2.3)
6
6
  chamber (~> 2.9)
7
7
  daemons
@@ -16,9 +16,7 @@ GEM
16
16
  addressable (2.4.0)
17
17
  amq-protocol (2.0.1)
18
18
  ast (2.3.0)
19
- astrolabe (1.3.1)
20
- parser (~> 2.2)
21
- bunny (2.3.1)
19
+ bunny (2.4.0)
22
20
  amq-protocol (>= 2.0.1)
23
21
  chamber (2.9.0)
24
22
  hashie (~> 3.3)
@@ -45,7 +43,7 @@ GEM
45
43
  ast (~> 2.2)
46
44
  powerpack (0.1.1)
47
45
  rainbow (2.1.0)
48
- rake (11.1.2)
46
+ rake (11.2.2)
49
47
  rest-client (1.8.0)
50
48
  http-cookie (>= 1.0.2, < 2.0)
51
49
  mime-types (>= 1.16, < 3.0)
@@ -63,18 +61,19 @@ GEM
63
61
  diff-lcs (>= 1.2.0, < 2.0)
64
62
  rspec-support (~> 3.4.0)
65
63
  rspec-support (3.4.1)
66
- rubocop (0.32.1)
67
- astrolabe (~> 1.3)
68
- parser (>= 2.2.2.5, < 3.0)
64
+ rubocop (0.40.0)
65
+ parser (>= 2.3.1.0, < 3.0)
69
66
  powerpack (~> 0.1)
70
67
  rainbow (>= 1.99.1, < 3.0)
71
- ruby-progressbar (~> 1.4)
68
+ ruby-progressbar (~> 1.7)
69
+ unicode-display_width (~> 1.0, >= 1.0.1)
72
70
  ruby-progressbar (1.8.1)
73
71
  terminal-table (1.6.0)
74
72
  thor (0.19.1)
75
73
  unf (0.1.4)
76
74
  unf_ext
77
75
  unf_ext (0.0.7.2)
76
+ unicode-display_width (1.0.5)
78
77
 
79
78
  PLATFORMS
80
79
  ruby
@@ -85,7 +84,7 @@ DEPENDENCIES
85
84
  pushyd!
86
85
  rake
87
86
  rspec
88
- rubocop (~> 0.32.0)
87
+ rubocop
89
88
 
90
89
  BUNDLED WITH
91
90
  1.11.2
data/bin/pushyd CHANGED
@@ -6,54 +6,54 @@ begin
6
6
  require "optparse"
7
7
  require 'daemons'
8
8
  require_relative "../lib/pushyd/conf"
9
- rescue LoadError
10
- raise "EXITING: some basic libs were not found"
9
+ rescue LoadError => e
10
+ raise "EXITING: some basic libs were not found (#{e.message})"
11
11
  end
12
- include PushyDaemon
13
12
 
14
13
 
15
14
  # Handle configuration
16
- APP_ROOT = File.expand_path(File.dirname(__FILE__) + "/../")
17
15
  begin
18
16
  # Defaults
19
17
  cmd_config = nil
20
18
  cmd_logfile = nil
21
- cmd_env = "production"
22
- cmd_dump = false
19
+
20
+ # Init Chamber-based configuration from Gemspec
21
+ Conf.init File.dirname(__FILE__) + "/../"
22
+ Conf.app_env = "production"
23
23
 
24
24
  # Parse options and check compliance
25
25
  OptionParser.new do |opts|
26
26
  opts.banner = "Usage: #{File.basename $PROGRAM_NAME} [options] start|stop"
27
27
  opts.on("-l", "--log LOGFILE") { |path| cmd_logfile = File.expand_path(path)}
28
28
  opts.on("-c", "--config CONFIGFILE") { |path| cmd_config = File.expand_path(path)}
29
- opts.on("-e", "--environment ENV") { |env| cmd_env = env }
30
- opts.on("-d", "--dump") { cmd_dump = true }
31
- opts.on("", "--dev") { cmd_env = "development" }
29
+ opts.on("-e", "--environment ENV") { |env| Conf.app_env = env }
30
+ opts.on("", "--dev") { Conf.app_env = "development" }
32
31
  end.order!(ARGV)
33
32
 
34
- # Build Chamber-based configuration from Gemspec with initial context
35
- Conf.prepare root: APP_ROOT, gemspec: "pushyd", env: cmd_env, config: cmd_config, logfile: cmd_logfile
33
+ # Load Chamber-based configuration
34
+ Conf.prepare config: cmd_config, logfile: cmd_logfile
35
+
36
+ # Override log file
37
+ Conf[:log] ||= {}
38
+ Conf[:log][:file] = cmd_logfile.to_s if cmd_logfile
36
39
 
37
40
  rescue OptionParser::InvalidOption => e
38
41
  abort "EXITING: InvalidOption: #{e.message} \n #{e.backtrace.to_yaml}"
39
- rescue PushyDaemon::ConfigParseError => e
42
+ rescue ConfigParseError => e
40
43
  abort "EXITING: ConfigParseError: #{e.message} \n #{e.backtrace.to_yaml}"
41
44
  rescue StandardError => e
42
45
  abort "EXITING: StandardError: #{e.message} \n #{e.backtrace.to_yaml}"
46
+ else
43
47
  end
44
48
 
45
- # Display final configuration
46
- puts "--- #{Conf.name} #{Conf.version}"
47
- puts "Environment \t #{Conf.env}"
49
+ # Display final configuration, quit if config dump requested
50
+ puts "--- #{Conf.app_name} #{Conf.app_ver}"
51
+ puts "Environment \t #{Conf.app_env}"
48
52
  puts "Config files \t #{Conf.files}"
49
- puts "Loging to file \t #{Conf.log.file}"
50
- puts "YAML Parser \t #{YAML.name}"
51
-
52
- # Quit if config dump requested
53
- if cmd_dump
54
- puts Conf.dump
55
- exit(0)
56
- end
53
+ puts "Started at \t #{Conf.app_started}"
54
+ puts "Loging to file \t #{Conf[:log][:file]}" if Conf[:log].is_a? Enumerable
55
+ puts
56
+ puts Conf.dump
57
57
 
58
58
  # Run daemon
59
59
  run_options = {
data/lib/pushyd/conf.rb CHANGED
@@ -1,104 +1,147 @@
1
1
  require "chamber"
2
2
 
3
- module PushyDaemon
4
- class ConfigMissingParameter < StandardError; end
5
- class ConfigOtherError < StandardError; end
6
- class ConfigParseError < StandardError; end
7
-
8
- class Conf
9
- extend Chamber
10
-
11
- class << self
12
- attr_reader :name
13
- attr_reader :spec
14
- attr_reader :files
15
- attr_reader :version
16
- attr_reader :env
17
- attr_reader :host
18
- end
3
+ # FIXME: files named with hyphens will not be found by Chamber for now
4
+ # FIXME: reloading of configuration from API
19
5
 
20
- def self.prepare args = {}
21
- # Context parameters
22
- fail PushyDaemon::ConfigMissingParameter, "missing root" unless (@root = args[:root])
23
- fail PushyDaemon::ConfigMissingParameter, "missing env" unless (@env = args[:env])
24
-
25
- # Gemspec parameter
26
- gemspec_path = "#{args[:root]}/#{args[:gemspec]}.gemspec"
27
- fail PushyDaemon::ConfigMissingParameter, "missing gemspec" unless args[:gemspec]
28
- fail PushyDaemon::ConfigMissingParameter, "gemspec file not found: #{gemspec_path}" unless File.exist?(gemspec_path)
29
-
30
- # Init host if missing
31
- @host ||= `hostname`.to_s.chomp.split(".").first
32
-
33
- # Load Gemspec
34
- @spec = Gem::Specification::load gemspec_path
35
- @name = @spec.name
36
- @version = @spec.version
37
- fail PushyDaemon::ConfigMissingParameter, "missing name" unless @name
38
-
39
- # Init Chamber (defaults, etc, cmdline)
40
- @files = ["#{args[:root]}/defaults.yml"]
41
- @files << File.expand_path("/etc/#{@name}.yml")
42
- @files << args[:config].to_s if args[:config]
43
-
44
- # Load configuration files
45
- load files: @files, namespaces: { environment: @env }
46
-
47
- # Override some values
48
- self[:log] ||= {}
49
- if args[:logfile]
50
- self[:log][:file] = args[:logfile].to_s
51
- end
52
-
53
- # Init New Relic
54
- prepare_newrelic self[:newrelic]
55
-
56
- # Try to access any key to force parsing of the files
57
- self[:dummy]
58
-
59
- rescue Psych::SyntaxError => e
60
- fail PushyDaemon::ConfigParseError, e.message
61
- rescue StandardError => e
62
- fail PushyDaemon::ConfigOtherError, "#{e.message} \n #{e.backtrace.to_yaml}"
63
- end
6
+ class ConfigMissingParameter < StandardError; end
7
+ class ConfigOtherError < StandardError; end
8
+ class ConfigParseError < StandardError; end
9
+ class ConfigMultipleGemspec < StandardError; end
10
+ class ConfigMissingGemspec < StandardError; end
64
11
 
65
- def self.dump
66
- self.to_hash.to_yaml
67
- end
12
+ class Conf
13
+ extend Chamber
68
14
 
69
- def Conf.newrelic_enabled?
70
- !!self[:newrelic]
71
- end
15
+ class << self
16
+ attr_accessor :app_env
17
+
18
+ attr_reader :app_root
19
+ attr_reader :app_libs
20
+
21
+ attr_reader :app_name
22
+ attr_reader :app_ver
23
+ attr_reader :app_started
24
+
25
+ attr_reader :spec
26
+ attr_reader :files
27
+ attr_reader :host
28
+ attr_reader :pidfile
29
+
30
+ end
72
31
 
73
- protected
32
+ def self.init app_root = nil
33
+ # Defaults, hostname
34
+ @files = []
35
+ @app_env = "production"
36
+ @app_started = Time.now
37
+ @host = `hostname`.to_s.chomp.split(".").first
38
+
39
+ # Grab app root
40
+ @app_root = File.expand_path( File.dirname(__FILE__) + "/../../")
41
+ @app_libs = File.expand_path( File.dirname(__FILE__) )
42
+
43
+ # Try to find any gemspec file
44
+ matches = Dir["#{@app_root}/*.gemspec"]
45
+ fail ConfigMissingGemspec, "gemspec file not found: #{gemspec_path}" if matches.size < 1
46
+ fail ConfigMultipleGemspec, "gemspec file not found: #{gemspec_path}" if matches.size > 1
47
+
48
+ # Load Gemspec (just the only match)
49
+ @spec = Gem::Specification::load(matches.first)
50
+ @app_name = @spec.name
51
+ @app_ver = @spec.version
52
+ fail ConfigMissingParameter, "gemspec: missing name" unless @app_name
53
+ fail ConfigMissingParameter, "gemspec: missing version" unless @app_ver
54
+
55
+ # Add config files
56
+ add_default_config
57
+ add_etc_config
58
+ end
59
+
60
+ def self.prepare args = {}
61
+ # Add extra config file
62
+ add_extra_config args[:config]
74
63
 
75
- def self.prepare_newrelic section
76
- unless section.is_a?(Hash)
77
- # puts "prepare_newrelic: no config found"
78
- ENV["NEWRELIC_AGENT_ENABLED"] = "false"
79
- return
80
- end
81
- # puts "prepare_newrelic: #{section.inspect}"
64
+ # Load configuration files
65
+ load_files
82
66
 
83
- # Enable GC profiler
84
- GC::Profiler.enable
67
+ # Init New Relic
68
+ prepare_newrelic self[:newrelic], self.at(:logs, :newrelic)
85
69
 
86
- # Enable module
87
- ENV["NEWRELIC_AGENT_ENABLED"] = "true"
88
- ENV["NEW_RELIC_MONITOR_MODE"] = "true"
70
+ # Prepare PID file is not present
71
+ prepare_pidfile
89
72
 
90
- # License
91
- ENV["NEW_RELIC_LICENSE_KEY"] = section[:licence].to_s
73
+ # Try to access any key to force parsing of the files
74
+ self[:dummy]
92
75
 
93
- # Appname
94
- platform = section[:platform] || self.host
95
- section[:app_name] ||= "#{self.name}-#{platform}-#{self.env}"
96
- ENV["NEW_RELIC_APP_NAME"] = section[:app_name].to_s
76
+ rescue Psych::SyntaxError => e
77
+ fail ConfigParseError, e.message
78
+ rescue StandardError => e
79
+ fail ConfigOtherError, "#{e.message} \n #{e.backtrace.to_yaml}"
80
+ end
81
+
82
+ def self.reload!
83
+ load_files
84
+ end
85
+
86
+ def self.dump
87
+ to_hash.to_yaml(indent: 4, useheader: true, useversion: false )
88
+ end
89
+
90
+ # Direct access to any depth
91
+ def self.at *path
92
+ path.reduce(Conf) { |m, key| m && m[key.to_s] }
93
+ end
97
94
 
98
- # Logfile
99
- ENV["NEW_RELIC_LOG"] = section[:logfile].to_s
95
+ def self.newrelic_enabled?
96
+ !!self[:newrelic]
97
+ end
98
+
99
+ protected
100
+
101
+ def self.load_files
102
+ load files: @files, namespaces: { environment: @app_env }
103
+ end
104
+
105
+ def self.add_default_config
106
+ @files << "#{@app_root}/defaults.yml" if @app_root
107
+ end
108
+
109
+ def self.add_etc_config
110
+ @files << File.expand_path("/etc/#{@app_name}.yml") if @app_name
111
+ end
112
+
113
+ def self.add_extra_config path
114
+ @files << File.expand_path(path) if path
115
+ end
116
+
117
+ def self.prepare_pidfile
118
+ self[:pidfile] ||= "/tmp/#{@app_name}-#{@host}-#{self[:port]}.pid"
119
+ end
120
+
121
+ def self.prepare_newrelic section, logfile
122
+ # Disable NewRelic if no config present
123
+ unless section.is_a?(Hash)
124
+ ENV["NEWRELIC_AGENT_ENABLED"] = "false"
125
+ return
100
126
  end
101
127
 
128
+ # Enable GC profiler
129
+ GC::Profiler.enable
102
130
 
131
+ # Enable module
132
+ ENV["NEWRELIC_AGENT_ENABLED"] = "true"
133
+ ENV["NEW_RELIC_MONITOR_MODE"] = "true"
134
+
135
+ # License
136
+ ENV["NEW_RELIC_LICENSE_KEY"] = section[:licence].to_s
137
+
138
+ # Appname
139
+ platform = section[:platform] || self.host
140
+ section[:app_name] ||= "#{@app_name}-#{platform}-#{@app_env}"
141
+ ENV["NEW_RELIC_APP_NAME"] = section[:app_name].to_s
142
+
143
+ # Logfile
144
+ ENV["NEW_RELIC_LOG"] = logfile.to_s if logfile
103
145
  end
146
+
104
147
  end
data/lib/pushyd/daemon.rb CHANGED
@@ -18,6 +18,8 @@ module PushyDaemon
18
18
  loop do
19
19
  end
20
20
 
21
+ rescue EndpointConnectionError => e
22
+ abort "EXITING #{e.class}: #{e.message}"
21
23
  rescue Errno::EACCES, StandardError => e
22
24
  abort "EXITING #{e.class}: #{e.message} \n #{e.backtrace.to_yaml}"
23
25
  end
data/pushyd.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  # Project version
4
- spec.version = "0.4.2"
4
+ spec.version = "0.5.0"
5
5
 
6
6
  # Project description
7
7
  spec.name = "pushyd"
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
26
  spec.add_development_dependency "http", "~> 2.0"
27
- spec.add_development_dependency "rubocop", "~> 0.32.0"
27
+ spec.add_development_dependency "rubocop"
28
28
  # spec.add_development_dependency "pry"
29
29
 
30
30
  # Runtime dependencies
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushyd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.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-06-10 00:00:00.000000000 Z
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.32.0
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 0.32.0
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: daemons
85
85
  requirement: !ruby/object:Gem::Requirement