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 +4 -4
- data/lib/uc/config.rb +13 -30
- data/lib/uc/server.rb +7 -8
- data/lib/uc/unicorn/api.rb +1 -0
- data/lib/uc/unicorn/paths.rb +9 -11
- data/lib/uc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 141ad16243a2fb649fb60a99a714a6136932b0c4
|
4
|
+
data.tar.gz: 210b4c5f005409f866e050999c209c61987f8496
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
83
|
-
|
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
|
-
|
100
|
+
logger.debug "loading env from #{path}"
|
111
101
|
h = YAML.load_file(path)
|
112
|
-
|
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
|
-
|
118
|
-
|
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
|
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.
|
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
|
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
|
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
|
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
|
|
data/lib/uc/unicorn/api.rb
CHANGED
@@ -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
|
data/lib/uc/unicorn/paths.rb
CHANGED
@@ -14,27 +14,27 @@ module Uc
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def stdout_log
|
17
|
-
|
17
|
+
abs_path "log/unicorn.stdout.log"
|
18
18
|
end
|
19
19
|
|
20
20
|
def stderr_log
|
21
|
-
|
21
|
+
abs_path "log/unicorn.stderr.log"
|
22
22
|
end
|
23
23
|
|
24
24
|
def socket
|
25
|
-
|
25
|
+
abs_path "tmp/sockets/unicorn.sock"
|
26
26
|
end
|
27
27
|
|
28
28
|
def pid_file
|
29
|
-
|
29
|
+
abs_path "tmp/pids/unicorn.pid"
|
30
30
|
end
|
31
31
|
|
32
32
|
def lock_file
|
33
|
-
|
33
|
+
abs_path "tmp/unicorn.lock"
|
34
34
|
end
|
35
35
|
|
36
36
|
def unicorn_config
|
37
|
-
|
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
|
47
|
-
|
48
|
-
|
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