foreman 0.9.0.beta.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/data/example/{Pstypes → Procfile} +0 -0
- data/lib/foreman.rb +1 -1
- data/lib/foreman/cli.rb +10 -10
- data/lib/foreman/engine.rb +22 -9
- data/man/foreman.1 +10 -10
- data/spec/foreman/cli_spec.rb +8 -8
- data/spec/foreman/engine_spec.rb +10 -10
- data/spec/spec_helper.rb +2 -2
- metadata +9 -13
File without changes
|
data/lib/foreman.rb
CHANGED
data/lib/foreman/cli.rb
CHANGED
@@ -5,7 +5,7 @@ require "thor"
|
|
5
5
|
|
6
6
|
class Foreman::CLI < Thor
|
7
7
|
|
8
|
-
class_option :
|
8
|
+
class_option :procfile, :type => :string, :aliases => "-f", :desc => "Default: Procfile"
|
9
9
|
|
10
10
|
desc "start [PROCESS]", "Start the application, or a specific process"
|
11
11
|
|
@@ -14,7 +14,7 @@ class Foreman::CLI < Thor
|
|
14
14
|
:banner => '"alpha=5,bar=3"'
|
15
15
|
|
16
16
|
def start(process=nil)
|
17
|
-
|
17
|
+
check_procfile!
|
18
18
|
|
19
19
|
if process
|
20
20
|
engine.execute(process, options)
|
@@ -33,7 +33,7 @@ class Foreman::CLI < Thor
|
|
33
33
|
:banner => '"alpha=5,bar=3"'
|
34
34
|
|
35
35
|
def export(format, location=nil)
|
36
|
-
|
36
|
+
check_procfile!
|
37
37
|
|
38
38
|
formatter = case format
|
39
39
|
when "upstart" then Foreman::Export::Upstart
|
@@ -49,16 +49,16 @@ class Foreman::CLI < Thor
|
|
49
49
|
|
50
50
|
private ######################################################################
|
51
51
|
|
52
|
-
def
|
53
|
-
error("#{
|
52
|
+
def check_procfile!
|
53
|
+
error("#{procfile} does not exist.") unless File.exist?(procfile)
|
54
54
|
end
|
55
55
|
|
56
56
|
def engine
|
57
|
-
@engine ||= Foreman::Engine.new(
|
57
|
+
@engine ||= Foreman::Engine.new(procfile)
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
options[:
|
60
|
+
def procfile
|
61
|
+
options[:procfile] || "Procfile"
|
62
62
|
end
|
63
63
|
|
64
64
|
private ######################################################################
|
@@ -68,8 +68,8 @@ private ######################################################################
|
|
68
68
|
exit 1
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
72
|
-
File.exist?(
|
71
|
+
def procfile_exists?(procfile)
|
72
|
+
File.exist?(procfile)
|
73
73
|
end
|
74
74
|
|
75
75
|
end
|
data/lib/foreman/engine.rb
CHANGED
@@ -8,34 +8,47 @@ require "fileutils"
|
|
8
8
|
|
9
9
|
class Foreman::Engine
|
10
10
|
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :procfile
|
12
12
|
attr_reader :directory
|
13
13
|
|
14
14
|
extend Term::ANSIColor
|
15
15
|
|
16
16
|
COLORS = [ cyan, yellow, green, magenta, red ]
|
17
17
|
|
18
|
-
def initialize(
|
19
|
-
@
|
20
|
-
@directory = File.expand_path(File.dirname(
|
18
|
+
def initialize(procfile)
|
19
|
+
@procfile = read_procfile(procfile)
|
20
|
+
@directory = File.expand_path(File.dirname(procfile))
|
21
21
|
end
|
22
22
|
|
23
23
|
def processes
|
24
24
|
@processes ||= begin
|
25
|
-
|
25
|
+
@order = []
|
26
|
+
procfile.split("\n").inject({}) do |hash, line|
|
26
27
|
next if line.strip == ""
|
27
28
|
name, command = line.split(" ", 2)
|
28
29
|
process = Foreman::Process.new(name, command)
|
29
30
|
process.color = next_color
|
31
|
+
@order << process.name
|
30
32
|
hash.update(process.name => process)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
37
|
+
def process_order
|
38
|
+
processes
|
39
|
+
@order
|
40
|
+
end
|
41
|
+
|
42
|
+
def processes_in_order
|
43
|
+
process_order.map do |name|
|
44
|
+
[name, processes[name]]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
35
48
|
def start(options={})
|
36
49
|
proctitle "ruby: foreman master"
|
37
50
|
|
38
|
-
|
51
|
+
processes_in_order.each do |name, process|
|
39
52
|
fork process, options
|
40
53
|
end
|
41
54
|
|
@@ -78,7 +91,7 @@ private ######################################################################
|
|
78
91
|
run(process)
|
79
92
|
end
|
80
93
|
|
81
|
-
info "started with pid #{pid}
|
94
|
+
info "started with pid #{pid}", process
|
82
95
|
running_processes[pid] = process
|
83
96
|
end
|
84
97
|
|
@@ -144,8 +157,8 @@ private ######################################################################
|
|
144
157
|
$0 = title
|
145
158
|
end
|
146
159
|
|
147
|
-
def
|
148
|
-
File.read(
|
160
|
+
def read_procfile(procfile)
|
161
|
+
File.read(procfile)
|
149
162
|
end
|
150
163
|
|
151
164
|
def watch_for_termination
|
data/man/foreman.1
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
.\" generated with Ronn/v0.7.3
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.
|
4
|
-
.TH "FOREMAN" "1" "October 2010" "Foreman 0.
|
4
|
+
.TH "FOREMAN" "1" "October 2010" "Foreman 0.9.0.beta.1" "Foreman Manual"
|
5
5
|
.
|
6
6
|
.SH "NAME"
|
7
|
-
\fBforeman\fR \- manage
|
7
|
+
\fBforeman\fR \- manage Psfile\-based applications
|
8
8
|
.
|
9
9
|
.SH "SYNOPSIS"
|
10
10
|
\fBforeman start [process]\fR
|
@@ -13,13 +13,13 @@
|
|
13
13
|
\fBforeman export <format> [location]\fR
|
14
14
|
.
|
15
15
|
.SH "DESCRIPTION"
|
16
|
-
\fBForeman\fR is a manager for
|
16
|
+
\fBForeman\fR is a manager for Psfile\-based applications\. Its aim is to abstract away the details of the Psfile format, and allow you to either run your application directly or export it to some other process management format\.
|
17
17
|
.
|
18
18
|
.SH "RUNNING"
|
19
19
|
\fBforeman start\fR is used to run your application directly from the command line\.
|
20
20
|
.
|
21
21
|
.P
|
22
|
-
If no additional parameters are passed, foreman will run one instance of each type of process defined in your
|
22
|
+
If no additional parameters are passed, foreman will run one instance of each type of process defined in your Psfile\.
|
23
23
|
.
|
24
24
|
.P
|
25
25
|
If a parameter is passed, foreman will run one instance of the specified application type\.
|
@@ -68,8 +68,8 @@ Specify the user the application should be run as\. Defaults to the app name
|
|
68
68
|
These options control all modes of foreman\'s operation\.
|
69
69
|
.
|
70
70
|
.TP
|
71
|
-
\fB\-f\fR, \fB\-\-
|
72
|
-
Specify an alternate location for the application\'s
|
71
|
+
\fB\-f\fR, \fB\-\-psfile\fR
|
72
|
+
Specify an alternate location for the application\'s Psfile\. This file\'s containing directory will be assumed to be the root directory of the application\.
|
73
73
|
.
|
74
74
|
.SH "EXPORT FORMATS"
|
75
75
|
foreman currently supports the following output formats:
|
@@ -110,8 +110,8 @@ Will create a series of upstart scripts in the location you specify\. Scripts wi
|
|
110
110
|
.P
|
111
111
|
\fBrestart appname\-processname\-3\fR
|
112
112
|
.
|
113
|
-
.SH "
|
114
|
-
A
|
113
|
+
.SH "PSFILE"
|
114
|
+
A Psfile should contain both a name for the process and the command used to run it\.
|
115
115
|
.
|
116
116
|
.IP "" 4
|
117
117
|
.
|
@@ -151,13 +151,13 @@ $ foreman export upstart /etc/init
|
|
151
151
|
.IP "" 0
|
152
152
|
.
|
153
153
|
.P
|
154
|
-
Run one process type from the application defined in a specific
|
154
|
+
Run one process type from the application defined in a specific Psfile:
|
155
155
|
.
|
156
156
|
.IP "" 4
|
157
157
|
.
|
158
158
|
.nf
|
159
159
|
|
160
|
-
$ foreman start alpha \-p ~/
|
160
|
+
$ foreman start alpha \-p ~/myapp/Psfile
|
161
161
|
.
|
162
162
|
.fi
|
163
163
|
.
|
data/spec/foreman/cli_spec.rb
CHANGED
@@ -5,17 +5,17 @@ describe "Foreman::CLI" do
|
|
5
5
|
subject { Foreman::CLI.new }
|
6
6
|
|
7
7
|
describe "start" do
|
8
|
-
describe "with a non-existent
|
8
|
+
describe "with a non-existent Procfile" do
|
9
9
|
it "prints an error" do
|
10
|
-
mock_error(subject, "
|
10
|
+
mock_error(subject, "Procfile does not exist.") do
|
11
11
|
dont_allow.instance_of(Foreman::Engine).start
|
12
12
|
subject.start
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe "with a
|
18
|
-
before(:each) {
|
17
|
+
describe "with a Procfile" do
|
18
|
+
before(:each) { write_procfile }
|
19
19
|
|
20
20
|
it "runs successfully" do
|
21
21
|
dont_allow(subject).error
|
@@ -26,17 +26,17 @@ describe "Foreman::CLI" do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "export" do
|
29
|
-
describe "with a non-existent
|
29
|
+
describe "with a non-existent Procfile" do
|
30
30
|
it "prints an error" do
|
31
|
-
mock_error(subject, "
|
31
|
+
mock_error(subject, "Procfile does not exist.") do
|
32
32
|
dont_allow.instance_of(Foreman::Engine).export
|
33
33
|
subject.export("testapp")
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe "with a
|
39
|
-
before(:each) {
|
38
|
+
describe "with a Procfile" do
|
39
|
+
before(:each) { write_procfile }
|
40
40
|
|
41
41
|
describe "with an invalid formatter" do
|
42
42
|
it "prints an error" do
|
data/spec/foreman/engine_spec.rb
CHANGED
@@ -2,18 +2,18 @@ require "spec_helper"
|
|
2
2
|
require "foreman/engine"
|
3
3
|
|
4
4
|
describe "Foreman::Engine" do
|
5
|
-
subject { Foreman::Engine.new("
|
5
|
+
subject { Foreman::Engine.new("Procfile") }
|
6
6
|
|
7
7
|
describe "initialize" do
|
8
|
-
describe "without an existing
|
8
|
+
describe "without an existing Procfile" do
|
9
9
|
it "raises an error" do
|
10
10
|
lambda { subject }.should raise_error
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe "with a
|
14
|
+
describe "with a Procfile" do
|
15
15
|
it "reads the processes" do
|
16
|
-
|
16
|
+
write_procfile
|
17
17
|
subject.processes["alpha"].command.should == "./alpha"
|
18
18
|
subject.processes["bravo"].command.should == "./bravo"
|
19
19
|
end
|
@@ -22,7 +22,7 @@ describe "Foreman::Engine" do
|
|
22
22
|
|
23
23
|
describe "start" do
|
24
24
|
it "forks the processes" do
|
25
|
-
|
25
|
+
write_procfile
|
26
26
|
mock(subject).fork(subject.processes["alpha"], {})
|
27
27
|
mock(subject).fork(subject.processes["bravo"], {})
|
28
28
|
mock(subject).watch_for_termination
|
@@ -30,10 +30,10 @@ describe "Foreman::Engine" do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "handles concurrency" do
|
33
|
-
|
34
|
-
mock(subject).fork_individual(subject.processes["alpha"], 5000)
|
35
|
-
mock(subject).fork_individual(subject.processes["alpha"], 5001)
|
36
|
-
mock(subject).fork_individual(subject.processes["bravo"], 5100)
|
33
|
+
write_procfile
|
34
|
+
mock(subject).fork_individual(subject.processes["alpha"], 1, 5000)
|
35
|
+
mock(subject).fork_individual(subject.processes["alpha"], 2, 5001)
|
36
|
+
mock(subject).fork_individual(subject.processes["bravo"], 1, 5100)
|
37
37
|
mock(subject).watch_for_termination
|
38
38
|
subject.start(:concurrency => "alpha=2")
|
39
39
|
end
|
@@ -41,7 +41,7 @@ describe "Foreman::Engine" do
|
|
41
41
|
|
42
42
|
describe "execute" do
|
43
43
|
it "runs the processes" do
|
44
|
-
|
44
|
+
write_procfile
|
45
45
|
mock(subject).fork(subject.processes["alpha"], {})
|
46
46
|
mock(subject).watch_for_termination
|
47
47
|
subject.execute("alpha")
|
data/spec/spec_helper.rb
CHANGED
@@ -24,8 +24,8 @@ def write_foreman_config(app)
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
File.open(
|
27
|
+
def write_procfile(procfile="Procfile")
|
28
|
+
File.open(procfile, "w") do |file|
|
29
29
|
file.puts "alpha ./alpha"
|
30
30
|
file.puts "bravo ./bravo"
|
31
31
|
end
|
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 59
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
9
|
- 0
|
10
|
-
|
11
|
-
- 1
|
12
|
-
version: 0.9.0.beta.1
|
10
|
+
version: 0.9.0
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- |
|
@@ -19,7 +17,7 @@ autorequire:
|
|
19
17
|
bindir: bin
|
20
18
|
cert_chain: []
|
21
19
|
|
22
|
-
date: 2010-
|
20
|
+
date: 2010-11-03 00:00:00 -07:00
|
23
21
|
default_executable:
|
24
22
|
dependencies:
|
25
23
|
- !ruby/object:Gem::Dependency
|
@@ -176,7 +174,7 @@ files:
|
|
176
174
|
- bin/foreman
|
177
175
|
- man/foreman.1
|
178
176
|
- README.markdown
|
179
|
-
- data/example/
|
177
|
+
- data/example/Procfile
|
180
178
|
- data/example/error
|
181
179
|
- data/example/log/neverdie.log
|
182
180
|
- data/example/ticker
|
@@ -220,14 +218,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
220
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
221
219
|
none: false
|
222
220
|
requirements:
|
223
|
-
- - "
|
221
|
+
- - ">="
|
224
222
|
- !ruby/object:Gem::Version
|
225
|
-
hash:
|
223
|
+
hash: 3
|
226
224
|
segments:
|
227
|
-
-
|
228
|
-
|
229
|
-
- 1
|
230
|
-
version: 1.3.1
|
225
|
+
- 0
|
226
|
+
version: "0"
|
231
227
|
requirements: []
|
232
228
|
|
233
229
|
rubyforge_project: nowarning
|