uc 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56f5b194b95797f2d533561b497e78a6f4db8316
4
- data.tar.gz: e6aa5f2d280d2a9aaeba67eec5baa0e043e437a0
3
+ metadata.gz: 141ad16243a2fb649fb60a99a714a6136932b0c4
4
+ data.tar.gz: 210b4c5f005409f866e050999c209c61987f8496
5
5
  SHA512:
6
- metadata.gz: 4272cad7ed70ad7a14df4204e1a1530a0426dc961ce4ca0f93d333587e65f8b7f37a746a483e658741358600a011940347fd273f37df838c726cdb2fa64480a4
7
- data.tar.gz: b511b802494945888ccc6d3f4d5e1e08186c7f82c58e34fcf39a69dd256489948f49b3089c8a21f42f00a2d8a136b637c085de4df9049f26235042add85fcafd
6
+ metadata.gz: 569fe945ce9abb05ce83e2dd83608373b4a59e5ce4c14aa8845d2ba396b8bef91ef4883a19e32842239c4d1396f7a1faba3fd4ba8bbaf43d38fa1feea0d547a3
7
+ data.tar.gz: 095c00a09327ebf4545f0e1f82d461f6b77447e79031847cb72bc545c299ae700397cb5cd49328eaafb6b42c4d826cc7ff2f639279b4209a6e405a408428f8e9
data/lib/uc/config.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'uc/logger'
2
2
  require 'uc/error'
3
+ require 'yaml'
3
4
 
4
5
  module Uc
5
6
  class Config
@@ -27,6 +28,8 @@ module Uc
27
28
  ready_wait: 5,
28
29
  listen: []
29
30
  }
31
+ load_env_yml "#{app_dir}/config/env.yml"
32
+ load_env_yml "#{app_dir}/.env.yml"
30
33
  read_from_file
31
34
  return @config
32
35
  end
@@ -79,47 +82,27 @@ module Uc
79
82
  config[:skip_clean_env] = value
80
83
  end
81
84
 
82
- def env_hash
83
- @env_hash ||= {}
84
- end
85
-
86
- def env(key, value)
87
- env_hash[key] = value
88
- end
89
-
90
- def env_yml(path, safe: false)
91
- @skip_autoload = true
92
- load_env_yml path, safe: safe
85
+ def env_yml(path, required: true)
86
+ load_env_yml(path, required: required)
93
87
  end
94
88
 
95
89
  def load_env
90
+ # all environment variables will be loaded on config parsing
96
91
  config
97
- if not @skip_autoload
98
- load_env_yml "#{app_dir}/config/env.yml", safe: true, override: false
99
- end
100
- env_hash.each do |k,v|
101
- ENV[k] = v.to_s
102
- end
103
92
  end
104
93
 
105
-
106
- def load_env_yml(path, safe: false, override: true)
94
+ def load_env_yml(path, required: false)
107
95
  if not File.readable? path
96
+ raise Error, "env file #{path} unreadable" if required
108
97
  logger.debug "skipped loading env from #{path}"
98
+ return {}
109
99
  end
110
- require 'yaml'
100
+ logger.debug "loading env from #{path}"
111
101
  h = YAML.load_file(path)
112
- env_hash.merge!(h) do |key, v1, v2|
113
- override ? v2 : v1
114
- end
115
- logger.debug "loaded env from #{path}"
102
+ h.each { |k,v| ENV[k] = v.to_s }
116
103
  rescue => e
117
- error_message = "failed to load env from #{path}: #{e.message}"
118
- if not safe
119
- raise ::Uc::Error, error_message
120
- else
121
- logger.debug error_message
122
- end
104
+ raise Error, "failed to load env from #{path} : #{e.message}" if required
105
+ logger.debug "failed to load env from #{path} : #{e.message}"
123
106
  end
124
107
 
125
108
  def read_from_file
data/lib/uc/server.rb CHANGED
@@ -32,7 +32,7 @@ module Uc
32
32
  puts "wont start 0 instances"
33
33
  return
34
34
  end
35
- ENV["UNICORN_APP_DIR"] = config.app_dir
35
+ ENV["UNICORN_APP_DIR"] = config[:working_dir]
36
36
  event_stream.expect :fin do
37
37
  cmd %{unicorn -c #{uconfig.path} -D -E #{rails_env} }, return_output: false,
38
38
  error_msg: "error starting unicorn"
@@ -63,7 +63,7 @@ module Uc
63
63
  init_once
64
64
  if config[:instances] == 0
65
65
  puts "0 instances specified: stopping"
66
- stop
66
+ stop if server_status.running?
67
67
  return
68
68
  end
69
69
  uconfig.generate_once
@@ -78,7 +78,7 @@ module Uc
78
78
 
79
79
  def print_config
80
80
  init_once
81
- config.to_h.each do |k,v|
81
+ config.each do |k,v|
82
82
  v = %{ "#{v}" } if not v.is_a? Numeric
83
83
  puts "#{k} #{v}"
84
84
  end
@@ -102,15 +102,15 @@ module Uc
102
102
  end
103
103
 
104
104
  def config
105
- @config ||= ::Uc::Config.new(app_dir)
105
+ @config ||= ::Uc::Config.new(app_dir).to_h
106
106
  end
107
107
 
108
108
  def unicorn_paths
109
- @unicorn_paths ||= ::Uc::Unicorn::Paths.new(config.app_dir)
109
+ @unicorn_paths ||= ::Uc::Unicorn::Paths.new(config[:working_dir])
110
110
  end
111
111
 
112
112
  def uconfig
113
- @uconfig ||= ::Uc::Unicorn::Config.new(config.to_h, unicorn_paths)
113
+ @uconfig ||= ::Uc::Unicorn::Config.new(config, unicorn_paths)
114
114
  end
115
115
 
116
116
  def lock
@@ -121,8 +121,7 @@ module Uc
121
121
  paths.validate_required
122
122
  Dir.chdir app_dir
123
123
  lock.acquire
124
- ::Uc::Logger.event_queue = config.event_queue_name
125
- config.load_env
124
+ ::Uc::Logger.event_queue = config[:event_queue]
126
125
  event_stream.debug_output = true if @debug
127
126
  end
128
127
 
@@ -97,6 +97,7 @@ module Uc; module Unicorn
97
97
 
98
98
  def load_original_env
99
99
  return if not @original_env.is_a? Hash
100
+ # add unicorn specific environment vars like UNICORN_FD
100
101
  ENV.select { |k,v| k =~ /\AUNICORN_/ }.each { |k,v| @original_env[k] = v }
101
102
  ENV.replace(@original_env)
102
103
  end
@@ -14,27 +14,27 @@ module Uc
14
14
  end
15
15
 
16
16
  def stdout_log
17
- rpath "log/unicorn.stdout.log"
17
+ abs_path "log/unicorn.stdout.log"
18
18
  end
19
19
 
20
20
  def stderr_log
21
- rpath "log/unicorn.stderr.log"
21
+ abs_path "log/unicorn.stderr.log"
22
22
  end
23
23
 
24
24
  def socket
25
- rpath "tmp/sockets/unicorn.sock"
25
+ abs_path "tmp/sockets/unicorn.sock"
26
26
  end
27
27
 
28
28
  def pid_file
29
- rpath "tmp/pids/unicorn.pid"
29
+ abs_path "tmp/pids/unicorn.pid"
30
30
  end
31
31
 
32
32
  def lock_file
33
- rpath "tmp/unicorn.lock"
33
+ abs_path "tmp/unicorn.lock"
34
34
  end
35
35
 
36
36
  def unicorn_config
37
- rpath "tmp/unicorn_config.rb"
37
+ abs_path "tmp/unicorn_config.rb"
38
38
  end
39
39
 
40
40
  def unicorn_template
@@ -43,11 +43,9 @@ module Uc
43
43
 
44
44
  private
45
45
 
46
- def rpath(path)
47
- "#{app_dir}/#{path}"
48
- end
49
-
50
-
46
+ def abs_path(path)
47
+ "#{app_dir}/#{path}"
48
+ end
51
49
 
52
50
  end
53
51
  end
data/lib/uc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Uc
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neeraj