foreman 0.15.0 → 0.16.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/README.markdown +19 -1
- data/data/example/ticker +1 -1
- data/lib/foreman/cli.rb +2 -2
- data/lib/foreman/engine.rb +32 -5
- data/lib/foreman/export.rb +1 -0
- data/lib/foreman/export/inittab.rb +1 -1
- data/lib/foreman/export/upstart.rb +1 -1
- data/lib/foreman/version.rb +1 -1
- data/man/foreman.1 +5 -1
- data/spec/foreman/engine_spec.rb +31 -6
- data/spec/foreman/export/upstart_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
data/README.markdown
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
# Foreman
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
gem install foreman
|
|
6
|
+
|
|
7
|
+
## Description
|
|
4
8
|
|
|
5
9
|
http://blog.daviddollar.org/2011/05/06/introducing-foreman.html
|
|
6
10
|
|
|
11
|
+
## Manual
|
|
12
|
+
|
|
7
13
|
See the [man page](http://ddollar.github.com/foreman) for usage.
|
|
8
14
|
|
|
15
|
+
## Author
|
|
16
|
+
|
|
17
|
+
David Dollar
|
|
18
|
+
|
|
19
|
+
## Contributors
|
|
20
|
+
|
|
21
|
+
Adam Wiggins
|
|
22
|
+
clifff
|
|
23
|
+
Dan Peterson
|
|
24
|
+
Keith Rarick
|
|
25
|
+
Ricardo Chimal, Jr
|
|
26
|
+
|
|
9
27
|
## License
|
|
10
28
|
|
|
11
29
|
MIT
|
data/data/example/ticker
CHANGED
data/lib/foreman/cli.rb
CHANGED
|
@@ -10,9 +10,9 @@ class Foreman::CLI < Thor
|
|
|
10
10
|
|
|
11
11
|
desc "start [PROCESS]", "Start the application, or a specific process"
|
|
12
12
|
|
|
13
|
+
method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env"
|
|
13
14
|
method_option :port, :type => :numeric, :aliases => "-p"
|
|
14
|
-
method_option :concurrency, :type => :string, :aliases => "-c",
|
|
15
|
-
:banner => '"alpha=5,bar=3"'
|
|
15
|
+
method_option :concurrency, :type => :string, :aliases => "-c", :banner => '"alpha=5,bar=3"'
|
|
16
16
|
|
|
17
17
|
def start(process=nil)
|
|
18
18
|
check_procfile!
|
data/lib/foreman/engine.rb
CHANGED
|
@@ -50,10 +50,12 @@ class Foreman::Engine
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def start(options={})
|
|
53
|
+
environment = read_environment(options[:env])
|
|
54
|
+
|
|
53
55
|
proctitle "ruby: foreman master"
|
|
54
56
|
|
|
55
57
|
processes_in_order.each do |name, process|
|
|
56
|
-
fork process, options
|
|
58
|
+
fork process, options, environment
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
trap("TERM") { puts "SIGTERM received"; kill_all("TERM") }
|
|
@@ -63,7 +65,9 @@ class Foreman::Engine
|
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
def execute(name, options={})
|
|
66
|
-
|
|
68
|
+
environment = read_environment(options[:env])
|
|
69
|
+
|
|
70
|
+
fork processes[name], options, environment
|
|
67
71
|
|
|
68
72
|
trap("TERM") { puts "SIGTERM received"; kill_all("TERM") }
|
|
69
73
|
trap("INT") { puts "SIGINT received"; kill_all("TERM") }
|
|
@@ -79,15 +83,17 @@ class Foreman::Engine
|
|
|
79
83
|
|
|
80
84
|
private ######################################################################
|
|
81
85
|
|
|
82
|
-
def fork(process, options={})
|
|
86
|
+
def fork(process, options={}, environment={})
|
|
83
87
|
concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])
|
|
84
88
|
|
|
85
89
|
1.upto(concurrency[process.name]) do |num|
|
|
86
|
-
fork_individual(process, num, port_for(process, num, options[:port]))
|
|
90
|
+
fork_individual(process, num, port_for(process, num, options[:port]), environment)
|
|
87
91
|
end
|
|
88
92
|
end
|
|
89
93
|
|
|
90
|
-
def fork_individual(process, num, port)
|
|
94
|
+
def fork_individual(process, num, port, environment)
|
|
95
|
+
environment.each { |k,v| ENV[k] = v }
|
|
96
|
+
|
|
91
97
|
ENV["PORT"] = port.to_s
|
|
92
98
|
ENV["PS"] = "#{process.name}.#{num}"
|
|
93
99
|
|
|
@@ -136,6 +142,11 @@ private ######################################################################
|
|
|
136
142
|
puts
|
|
137
143
|
end
|
|
138
144
|
|
|
145
|
+
def error(message)
|
|
146
|
+
puts "ERROR: #{message}"
|
|
147
|
+
exit 1
|
|
148
|
+
end
|
|
149
|
+
|
|
139
150
|
def longest_process_name
|
|
140
151
|
@longest_process_name ||= begin
|
|
141
152
|
longest = processes.keys.map { |name| name.length }.sort.last
|
|
@@ -190,4 +201,20 @@ private ######################################################################
|
|
|
190
201
|
puts "!!! e.g. web: thin start"
|
|
191
202
|
end
|
|
192
203
|
|
|
204
|
+
def read_environment(filename)
|
|
205
|
+
error "No such file: #{filename}" if filename && !File.exists?(filename)
|
|
206
|
+
filename ||= ".env"
|
|
207
|
+
environment = {}
|
|
208
|
+
|
|
209
|
+
if File.exists?(filename)
|
|
210
|
+
File.read(filename).split("\n").each do |line|
|
|
211
|
+
if line =~ /\A([A-Za-z_]+)=(.*)\z/
|
|
212
|
+
environment[$1] = $2
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
environment
|
|
218
|
+
end
|
|
219
|
+
|
|
193
220
|
end
|
data/lib/foreman/export.rb
CHANGED
data/lib/foreman/version.rb
CHANGED
data/man/foreman.1
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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" "May 2011" "Foreman 0.
|
|
4
|
+
.TH "FOREMAN" "1" "May 2011" "Foreman 0.15.0" "Foreman Manual"
|
|
5
5
|
.
|
|
6
6
|
.SH "NAME"
|
|
7
7
|
\fBforeman\fR \- manage Procfile\-based applications
|
|
@@ -68,6 +68,10 @@ 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\-e\fR, \fB\-\-env\fR
|
|
72
|
+
Specify a file containing the environment that should be set up for each child process\. The file should be key/value pairs separated by \fB=\fR, with one key/value pair per line\.
|
|
73
|
+
.
|
|
74
|
+
.TP
|
|
71
75
|
\fB\-f\fR, \fB\-\-procfile\fR
|
|
72
76
|
Specify an alternate location for the application\'s Procfile\. This file\'s containing directory will be assumed to be the root directory of the application\.
|
|
73
77
|
.
|
data/spec/foreman/engine_spec.rb
CHANGED
|
@@ -37,17 +37,17 @@ describe "Foreman::Engine" do
|
|
|
37
37
|
describe "start" do
|
|
38
38
|
it "forks the processes" do
|
|
39
39
|
write_procfile
|
|
40
|
-
mock(subject).fork(subject.processes["alpha"], {})
|
|
41
|
-
mock(subject).fork(subject.processes["bravo"], {})
|
|
40
|
+
mock(subject).fork(subject.processes["alpha"], {}, {})
|
|
41
|
+
mock(subject).fork(subject.processes["bravo"], {}, {})
|
|
42
42
|
mock(subject).watch_for_termination
|
|
43
43
|
subject.start
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "handles concurrency" do
|
|
47
47
|
write_procfile
|
|
48
|
-
mock(subject).fork_individual(subject.processes["alpha"], 1, 5000)
|
|
49
|
-
mock(subject).fork_individual(subject.processes["alpha"], 2, 5001)
|
|
50
|
-
mock(subject).fork_individual(subject.processes["bravo"], 1, 5100)
|
|
48
|
+
mock(subject).fork_individual(subject.processes["alpha"], 1, 5000, {})
|
|
49
|
+
mock(subject).fork_individual(subject.processes["alpha"], 2, 5001, {})
|
|
50
|
+
mock(subject).fork_individual(subject.processes["bravo"], 1, 5100, {})
|
|
51
51
|
mock(subject).watch_for_termination
|
|
52
52
|
subject.start(:concurrency => "alpha=2")
|
|
53
53
|
end
|
|
@@ -56,9 +56,34 @@ describe "Foreman::Engine" do
|
|
|
56
56
|
describe "execute" do
|
|
57
57
|
it "runs the processes" do
|
|
58
58
|
write_procfile
|
|
59
|
-
mock(subject).fork(subject.processes["alpha"], {})
|
|
59
|
+
mock(subject).fork(subject.processes["alpha"], {}, {})
|
|
60
60
|
mock(subject).watch_for_termination
|
|
61
61
|
subject.execute("alpha")
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
|
+
|
|
65
|
+
describe "environment" do
|
|
66
|
+
before(:each) do
|
|
67
|
+
write_procfile
|
|
68
|
+
stub(Process).fork
|
|
69
|
+
stub(subject).info
|
|
70
|
+
mock(subject).watch_for_termination
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should read if specified" do
|
|
74
|
+
File.open("/tmp/env", "w") { |f| f.puts("FOO=baz") }
|
|
75
|
+
subject.execute("alpha", :env => "/tmp/env")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "should fail if specified and doesnt exist" do
|
|
79
|
+
mock(subject).error("No such file: /tmp/env")
|
|
80
|
+
subject.execute("alpha", :env => "/tmp/env")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should read .env if none specified" do
|
|
84
|
+
File.open(".env", "w") { |f| f.puts("FOO=qoo") }
|
|
85
|
+
mock(subject).fork_individual(anything, anything, anything, { "FOO" => "qoo" })
|
|
86
|
+
subject.execute("bravo")
|
|
87
|
+
end
|
|
88
|
+
end
|
|
64
89
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: foreman
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.
|
|
5
|
+
version: 0.16.0
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- David Dollar
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-05-
|
|
13
|
+
date: 2011-05-13 00:00:00 -04:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|