procodile 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/procodile +10 -1
- data/lib/procodile/cli.rb +18 -7
- data/lib/procodile/config.rb +27 -12
- data/lib/procodile/control_session.rb +2 -0
- data/lib/procodile/message.rb +13 -0
- data/lib/procodile/process.rb +2 -1
- data/lib/procodile/status_cli_output.rb +9 -0
- data/lib/procodile/supervisor.rb +16 -0
- data/lib/procodile/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27d02f49619a2bed4bf6ea758c041de21c45a0a6
|
4
|
+
data.tar.gz: 185f7a035f673787062f20218fdfee23f14d0276
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84043a51c028bf6cd8e05cb07caa4639a0b8bc5c2acfae2889911561e5b221bb082cb77d9a7b1c12dc00acb286c5d5d96220e01212c9261d5c2f8169b848cd9c
|
7
|
+
data.tar.gz: 7bfa2f5d1d93f9aa244759acd064f4298392eb4b63763238e841fd9c607b51135d7482436f17a1c279e82d7985872f15dc1c4b8458e8d6e5c8f77a810eca75d6
|
data/bin/procodile
CHANGED
@@ -40,6 +40,15 @@ begin
|
|
40
40
|
opts.on("-r", "--root PATH", "The path to the root of your application") do |root|
|
41
41
|
options[:root] = root
|
42
42
|
end
|
43
|
+
|
44
|
+
opts.on("-e", "--environment NAME", "The config environment to use") do |name|
|
45
|
+
options[:environment] = name
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on("--procfile PATH", "The path to the Procfile (defaults to: Procfile)") do |path|
|
49
|
+
options[:procfile_path] = path
|
50
|
+
end
|
51
|
+
|
43
52
|
if cli.class.commands[command.to_sym] && option_block = cli.class.commands[command.to_sym][:options]
|
44
53
|
option_block.call(opts, cli)
|
45
54
|
end
|
@@ -51,7 +60,7 @@ end
|
|
51
60
|
|
52
61
|
begin
|
53
62
|
if command != 'help'
|
54
|
-
cli.config = Procodile::Config.new(options[:root] ? File.expand_path(options[:root]) : global_config['root'] || FileUtils.pwd)
|
63
|
+
cli.config = Procodile::Config.new(options[:root] ? File.expand_path(options[:root]) : global_config['root'] || FileUtils.pwd, options[:environment], options[:procfile_path])
|
55
64
|
end
|
56
65
|
cli.run(command)
|
57
66
|
rescue Procodile::Error => e
|
data/lib/procodile/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'procodile/version'
|
3
3
|
require 'procodile/error'
|
4
|
+
require 'procodile/message'
|
4
5
|
require 'procodile/supervisor'
|
5
6
|
require 'procodile/signal_handler'
|
6
7
|
require 'procodile/control_client'
|
@@ -45,12 +46,6 @@ module Procodile
|
|
45
46
|
# Help
|
46
47
|
#
|
47
48
|
|
48
|
-
command def proxy
|
49
|
-
require 'procodile/tcp_proxy'
|
50
|
-
p = Procodile::TCPProxy.new(Supervisor.new(@config, {}))
|
51
|
-
p.run
|
52
|
-
end
|
53
|
-
|
54
49
|
desc "Shows this help output"
|
55
50
|
command def help
|
56
51
|
puts "\e[45;37mWelcome to Procodile v#{Procodile::VERSION}\e[0m"
|
@@ -303,18 +298,34 @@ module Procodile
|
|
303
298
|
opts.on("--json", "Return the status as a JSON hash") do
|
304
299
|
cli.options[:json] = true
|
305
300
|
end
|
301
|
+
|
302
|
+
opts.on("--simple", "Return overall status") do
|
303
|
+
cli.options[:simple] = true
|
304
|
+
end
|
306
305
|
end
|
307
306
|
command def status
|
308
307
|
if supervisor_running?
|
309
308
|
status = ControlClient.run(@config.sock_path, 'status')
|
310
309
|
if @options[:json]
|
311
310
|
puts status.to_json
|
311
|
+
elsif @options[:simple]
|
312
|
+
if status['messages'].empty?
|
313
|
+
message = status['instances'].map { |p,i| "#{p}[#{i.size}]" }
|
314
|
+
puts "OK || #{message.join(', ')}"
|
315
|
+
else
|
316
|
+
message = status['messages'].map { |p| Message.parse(p) }.join(', ')
|
317
|
+
puts "Issues || #{message}"
|
318
|
+
end
|
312
319
|
else
|
313
320
|
require 'procodile/status_cli_output'
|
314
321
|
StatusCLIOutput.new(status).print_all
|
315
322
|
end
|
316
323
|
else
|
317
|
-
|
324
|
+
if @options[:simple]
|
325
|
+
puts "NotRunning || Procodile supervisor isn't running"
|
326
|
+
else
|
327
|
+
raise Error, "Procodile supervisor isn't running"
|
328
|
+
end
|
318
329
|
end
|
319
330
|
end
|
320
331
|
|
data/lib/procodile/config.rb
CHANGED
@@ -8,9 +8,12 @@ module Procodile
|
|
8
8
|
COLORS = [35, 31, 36, 32, 33, 34]
|
9
9
|
|
10
10
|
attr_reader :root
|
11
|
+
attr_reader :environment
|
11
12
|
|
12
|
-
def initialize(root)
|
13
|
+
def initialize(root, environment, procfile = nil)
|
13
14
|
@root = root
|
15
|
+
@environment = environment || 'production'
|
16
|
+
@procfile = procfile
|
14
17
|
unless File.exist?(procfile_path)
|
15
18
|
raise Error, "Procfile not found at #{procfile_path}"
|
16
19
|
end
|
@@ -56,7 +59,7 @@ module Procodile
|
|
56
59
|
end
|
57
60
|
|
58
61
|
def app_name
|
59
|
-
@app_name ||= local_options['app_name'] || options['app_name'] || 'Procodile'
|
62
|
+
@app_name ||= fetch(local_options['app_name']) || fetch(options['app_name']) || 'Procodile'
|
60
63
|
end
|
61
64
|
|
62
65
|
def processes
|
@@ -88,19 +91,15 @@ module Procodile
|
|
88
91
|
end
|
89
92
|
|
90
93
|
def environment_variables
|
91
|
-
(options['env'] || {}).merge(local_options['env'] || {})
|
92
|
-
end
|
93
|
-
|
94
|
-
def local_environment_variables
|
95
|
-
@local_environment_variables ||= local_options['env'] || {}
|
94
|
+
fetch_hash_values(options['env'] || {}).merge(fetch_hash_values(local_options['env'] || {}))
|
96
95
|
end
|
97
96
|
|
98
97
|
def pid_root
|
99
|
-
@pid_root ||= File.expand_path(local_options['pid_root'] || options['pid_root'] || 'pids', @root)
|
98
|
+
@pid_root ||= File.expand_path(fetch(local_options['pid_root']) || fetch(options['pid_root']) || 'pids', @root)
|
100
99
|
end
|
101
100
|
|
102
101
|
def log_path
|
103
|
-
@log_path ||= File.expand_path(local_options['log_path'] || options['log_path'] || 'procodile.log', @root)
|
102
|
+
@log_path ||= File.expand_path(fetch(local_options['log_path']) || fetch(options['log_path']) || 'procodile.log', @root)
|
104
103
|
end
|
105
104
|
|
106
105
|
def sock_path
|
@@ -110,15 +109,15 @@ module Procodile
|
|
110
109
|
private
|
111
110
|
|
112
111
|
def procfile_path
|
113
|
-
File.join(@root, 'Procfile')
|
112
|
+
@procfile_path || File.join(@root, 'Procfile')
|
114
113
|
end
|
115
114
|
|
116
115
|
def options_path
|
117
|
-
|
116
|
+
procfile_path + ".options"
|
118
117
|
end
|
119
118
|
|
120
119
|
def local_options_path
|
121
|
-
|
120
|
+
procfile_path + ".local"
|
122
121
|
end
|
123
122
|
|
124
123
|
def create_process(name, command, log_color)
|
@@ -127,5 +126,21 @@ module Procodile
|
|
127
126
|
process
|
128
127
|
end
|
129
128
|
|
129
|
+
def fetch(value, default = nil)
|
130
|
+
if value.is_a?(Hash)
|
131
|
+
value[@environment] || default
|
132
|
+
else
|
133
|
+
value || default
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def fetch_hash_values(hash)
|
138
|
+
hash.each_with_object({}) do |(key, value), h|
|
139
|
+
if value = fetch(value)
|
140
|
+
h[key] = value
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
130
145
|
end
|
131
146
|
end
|
@@ -63,7 +63,9 @@ module Procodile
|
|
63
63
|
processes = @supervisor.processes.keys.map(&:to_hash)
|
64
64
|
result = {
|
65
65
|
:version => Procodile::VERSION,
|
66
|
+
:messages => @supervisor.messages,
|
66
67
|
:root => @supervisor.config.root,
|
68
|
+
:environment => @supervisor.config.environment,
|
67
69
|
:app_name => @supervisor.config.app_name,
|
68
70
|
:supervisor => @supervisor.to_hash,
|
69
71
|
:instances => instances,
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Procodile
|
2
|
+
module Message
|
3
|
+
def self.parse(message)
|
4
|
+
case message['type']
|
5
|
+
when 'not_running'
|
6
|
+
"#{message['instance']} is not running (#{message['status']})"
|
7
|
+
when 'incorrect_quantity'
|
8
|
+
"#{message['process']} only has #{message['current']} instances (should have #{message['desired']})"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
data/lib/procodile/process.rb
CHANGED
@@ -12,10 +12,11 @@ module Procodile
|
|
12
12
|
attr_accessor :log_color
|
13
13
|
attr_accessor :removed
|
14
14
|
|
15
|
-
def initialize(config, name, command, options = {})
|
15
|
+
def initialize(config, name, command, environment, options = {})
|
16
16
|
@config = config
|
17
17
|
@name = name
|
18
18
|
@command = command
|
19
|
+
@environment = environment
|
19
20
|
@options = options
|
20
21
|
@log_color = 0
|
21
22
|
@instance_index = 0
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'procodile/message'
|
2
|
+
|
1
3
|
module Procodile
|
2
4
|
class StatusCLIOutput
|
3
5
|
|
@@ -13,6 +15,7 @@ module Procodile
|
|
13
15
|
def print_header
|
14
16
|
puts "Procodile Version " + @status['version'].to_s.color(34)
|
15
17
|
puts "Application Root " + "#{@status['root']}".color(34)
|
18
|
+
puts "Environment " + "#{@status['environment']}".color(34)
|
16
19
|
puts "Supervisor PID " + "#{@status['supervisor']['pid']}".color(34)
|
17
20
|
if time = @status['supervisor']['started_at']
|
18
21
|
time = Time.at(time)
|
@@ -29,6 +32,12 @@ module Procodile
|
|
29
32
|
puts " " + value.to_s
|
30
33
|
end
|
31
34
|
end
|
35
|
+
unless @status['messages'].empty?
|
36
|
+
puts
|
37
|
+
for message in @status['messages']
|
38
|
+
puts "\e[31m * #{Message.parse(message)}\e[0m"
|
39
|
+
end
|
40
|
+
end
|
32
41
|
end
|
33
42
|
|
34
43
|
def print_processes
|
data/lib/procodile/supervisor.rb
CHANGED
@@ -29,6 +29,7 @@ module Procodile
|
|
29
29
|
|
30
30
|
def start(&after_start)
|
31
31
|
Procodile.log nil, "system", "Procodile supervisor started with PID #{::Process.pid}"
|
32
|
+
Procodile.log nil, "system", "Environment is #{@config.environment}"
|
32
33
|
if @run_options[:respawn] == false
|
33
34
|
Procodile.log nil, "system", "Automatic respawning is disabled"
|
34
35
|
end
|
@@ -166,6 +167,21 @@ module Procodile
|
|
166
167
|
}
|
167
168
|
end
|
168
169
|
|
170
|
+
def messages
|
171
|
+
messages = []
|
172
|
+
processes.each do |process, process_instances|
|
173
|
+
if process.quantity != process_instances.size
|
174
|
+
messages << {:type => :incorrect_quantity, :process => process.name, :current => process_instances.size, :desired => process.quanaity}
|
175
|
+
end
|
176
|
+
for instance in process_instances
|
177
|
+
if instance.status != 'Running'
|
178
|
+
messages << {:type => :not_running, :instance => instance.description, :status => instance.status}
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
messages
|
183
|
+
end
|
184
|
+
|
169
185
|
def add_reader(instance, io)
|
170
186
|
@readers[io] = instance
|
171
187
|
@signal_handler.notice
|
data/lib/procodile/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: procodile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/procodile/error.rb
|
43
43
|
- lib/procodile/instance.rb
|
44
44
|
- lib/procodile/logger.rb
|
45
|
+
- lib/procodile/message.rb
|
45
46
|
- lib/procodile/process.rb
|
46
47
|
- lib/procodile/signal_handler.rb
|
47
48
|
- lib/procodile/status_cli_output.rb
|
@@ -68,9 +69,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
69
|
version: '0'
|
69
70
|
requirements: []
|
70
71
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.5.
|
72
|
+
rubygems_version: 2.5.1
|
72
73
|
signing_key:
|
73
74
|
specification_version: 4
|
74
75
|
summary: This gem will help you run Ruby processes from a Procfile on Linux servers
|
75
76
|
in the background.
|
76
77
|
test_files: []
|
78
|
+
has_rdoc:
|