foreman 0.6.0 → 0.7.0
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.
- data/lib/foreman.rb +1 -1
- data/lib/foreman/cli.rb +4 -5
- data/lib/foreman/engine.rb +30 -19
- data/lib/foreman/export/base.rb +1 -10
- data/lib/foreman/utils.rb +15 -0
- data/spec/foreman/cli_spec.rb +2 -5
- data/spec/foreman/engine_spec.rb +4 -3
- metadata +6 -5
data/lib/foreman.rb
CHANGED
data/lib/foreman/cli.rb
CHANGED
@@ -9,17 +9,16 @@ class Foreman::CLI < Thor
|
|
9
9
|
|
10
10
|
desc "start [PROCESS]", "Start the application, or a specific process"
|
11
11
|
|
12
|
-
method_option :
|
12
|
+
method_option :concurrency, :type => :string, :aliases => "-c",
|
13
|
+
:banner => '"alpha=5,bar=3"'
|
13
14
|
|
14
15
|
def start(process=nil)
|
15
16
|
check_procfile!
|
16
17
|
|
17
18
|
if process
|
18
|
-
engine.execute(process)
|
19
|
-
elsif options[:screen]
|
20
|
-
engine.screen
|
19
|
+
engine.execute(process, options)
|
21
20
|
else
|
22
|
-
engine.start
|
21
|
+
engine.start(options)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
data/lib/foreman/engine.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "foreman"
|
2
2
|
require "foreman/process"
|
3
|
+
require "foreman/utils"
|
3
4
|
require "pty"
|
4
5
|
require "tempfile"
|
5
6
|
require "term/ansicolor"
|
@@ -12,28 +13,42 @@ class Foreman::Engine
|
|
12
13
|
|
13
14
|
extend Term::ANSIColor
|
14
15
|
|
15
|
-
COLORS = [ cyan, yellow, green, magenta,
|
16
|
+
COLORS = [ cyan, yellow, green, magenta, red ]
|
16
17
|
|
17
18
|
def initialize(procfile)
|
18
19
|
@procfile = read_procfile(procfile)
|
19
20
|
@directory = File.expand_path(File.dirname(procfile))
|
20
21
|
end
|
21
22
|
|
22
|
-
def processes
|
23
|
+
def processes(concurrency=nil)
|
23
24
|
@processes ||= begin
|
25
|
+
concurrency = Foreman::Utils.parse_concurrency(concurrency)
|
26
|
+
|
24
27
|
procfile.split("\n").inject({}) do |hash, line|
|
25
28
|
next if line.strip == ""
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
name, command = line.split(" ", 2)
|
30
|
+
|
31
|
+
if concurrency[name] > 1 then
|
32
|
+
1.upto(concurrency[name]) do |num|
|
33
|
+
process = Foreman::Process.new("#{name}.#{num}", command)
|
34
|
+
process.color = next_color
|
35
|
+
hash[process.name] = process
|
36
|
+
end
|
37
|
+
else
|
38
|
+
process = Foreman::Process.new(name, command)
|
39
|
+
process.color = next_color
|
40
|
+
hash[process.name] = process
|
41
|
+
end
|
42
|
+
|
43
|
+
hash
|
29
44
|
end
|
30
45
|
end
|
31
46
|
end
|
32
47
|
|
33
|
-
def start
|
48
|
+
def start(options={})
|
34
49
|
proctitle "ruby: foreman master"
|
35
50
|
|
36
|
-
processes.each do |name, process|
|
51
|
+
processes(options[:concurrency]).each do |name, process|
|
37
52
|
fork process
|
38
53
|
end
|
39
54
|
|
@@ -43,21 +58,17 @@ class Foreman::Engine
|
|
43
58
|
watch_for_termination
|
44
59
|
end
|
45
60
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
61
|
+
def execute(name, options={})
|
62
|
+
processes(options[:concurrency]).values.select do |process|
|
63
|
+
process.name =~ /\A#{name}\.?\d*\Z/
|
64
|
+
end.each do |process|
|
65
|
+
fork process
|
51
66
|
end
|
52
|
-
tempfile.close
|
53
67
|
|
54
|
-
|
55
|
-
|
56
|
-
tempfile.delete
|
57
|
-
end
|
68
|
+
trap("TERM") { kill_and_exit("TERM") }
|
69
|
+
trap("INT") { kill_and_exit("INT") }
|
58
70
|
|
59
|
-
|
60
|
-
run(processes[name], false)
|
71
|
+
watch_for_termination
|
61
72
|
end
|
62
73
|
|
63
74
|
private ######################################################################
|
data/lib/foreman/export/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "foreman/export"
|
2
|
+
require "foreman/utils"
|
2
3
|
|
3
4
|
class Foreman::Export::Base
|
4
5
|
|
@@ -26,16 +27,6 @@ private ######################################################################
|
|
26
27
|
File.read(File.expand_path("../../../../export/#{name}", __FILE__))
|
27
28
|
end
|
28
29
|
|
29
|
-
def parse_concurrency(concurrency)
|
30
|
-
@concurrency ||= begin
|
31
|
-
pairs = concurrency.to_s.gsub(/\s/, "").split(",")
|
32
|
-
pairs.inject(Hash.new(1)) do |hash, pair|
|
33
|
-
process, amount = pair.split("=")
|
34
|
-
hash.update(process => amount.to_i)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
30
|
def port_for(base_port, app, num)
|
40
31
|
base_port ||= 5000
|
41
32
|
offset = engine.processes.keys.sort.index(app) * 100
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "foreman"
|
2
|
+
|
3
|
+
class Foreman::Utils
|
4
|
+
|
5
|
+
def self.parse_concurrency(concurrency)
|
6
|
+
@concurrency ||= begin
|
7
|
+
pairs = concurrency.to_s.gsub(/\s/, "").split(",")
|
8
|
+
pairs.inject(Hash.new(1)) do |hash, pair|
|
9
|
+
process, amount = pair.split("=")
|
10
|
+
hash.update(process => amount.to_i)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/foreman/cli_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe "Foreman::CLI" do
|
|
19
19
|
|
20
20
|
it "runs successfully" do
|
21
21
|
dont_allow(subject).error
|
22
|
-
mock.instance_of(Foreman::Engine).start
|
22
|
+
mock.instance_of(Foreman::Engine).start({})
|
23
23
|
subject.start
|
24
24
|
end
|
25
25
|
end
|
@@ -51,10 +51,7 @@ describe "Foreman::CLI" do
|
|
51
51
|
|
52
52
|
it "runs successfully" do
|
53
53
|
dont_allow(subject).error
|
54
|
-
mock.instance_of(Foreman::Export::Upstart).export("/tmp/foo", {
|
55
|
-
:concurrency => nil,
|
56
|
-
:name => nil
|
57
|
-
})
|
54
|
+
mock.instance_of(Foreman::Export::Upstart).export("/tmp/foo", {})
|
58
55
|
subject.export("upstart", "/tmp/foo")
|
59
56
|
end
|
60
57
|
end
|
data/spec/foreman/engine_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe "Foreman::Engine" do
|
|
10
10
|
lambda { subject }.should raise_error
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
describe "with a Procfile" do
|
15
15
|
it "reads the processes" do
|
16
16
|
write_procfile
|
@@ -19,7 +19,7 @@ describe "Foreman::Engine" do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe "start" do
|
24
24
|
it "forks the processes" do
|
25
25
|
write_procfile
|
@@ -33,7 +33,8 @@ describe "Foreman::Engine" do
|
|
33
33
|
describe "execute" do
|
34
34
|
it "runs the processes" do
|
35
35
|
write_procfile
|
36
|
-
mock(subject).
|
36
|
+
mock(subject).fork(subject.processes["alpha"])
|
37
|
+
mock(subject).watch_for_termination
|
37
38
|
subject.execute("alpha")
|
38
39
|
end
|
39
40
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 7
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Dollar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-19 00:00:00 -07:00
|
19
19
|
default_executable: foreman
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- lib/foreman/export/inittab.rb
|
153
153
|
- lib/foreman/export/upstart.rb
|
154
154
|
- lib/foreman/process.rb
|
155
|
+
- lib/foreman/utils.rb
|
155
156
|
- spec/foreman/cli_spec.rb
|
156
157
|
- spec/foreman/engine_spec.rb
|
157
158
|
- spec/foreman/export/upstart_spec.rb
|
@@ -160,7 +161,7 @@ files:
|
|
160
161
|
- spec/foreman_spec.rb
|
161
162
|
- spec/spec_helper.rb
|
162
163
|
- README.markdown
|
163
|
-
has_rdoc:
|
164
|
+
has_rdoc: true
|
164
165
|
homepage: http://github.com/ddollar/foreman
|
165
166
|
licenses: []
|
166
167
|
|