foreman 0.41.0-mingw32 → 0.44.0-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,15 @@
1
1
  <%
2
+ app_names = []
2
3
  engine.procfile.entries.each do |process|
3
4
  next if (conc = self.concurrency[process.name]) < 1
4
5
  1.upto(self.concurrency[process.name]) do |num|
5
6
  port = engine.port_for(process, num, self.port)
6
7
  name = if (conc > 1); "#{process.name}-#{num}" else process.name; end
7
- environment = (engine.environment.each_pair { |var,env| "#{var.upcase}=#{env}" }.to_a << "PORT=#{port}")
8
+ environment = (engine.environment.keys.sort.map{ |var| %{#{var.upcase}="#{engine.environment[var]}"} } + [%{PORT="#{port}"}])
9
+ app_name = "#{app}-#{name}"
10
+ app_names << app_name
8
11
  %>
9
- [program:<%= app %>-<%= name %>]
12
+ [program:<%= app_name %>]
10
13
  command=<%= process.command %>
11
14
  autostart=true
12
15
  autorestart=true
@@ -18,4 +21,7 @@ directory=<%= engine.directory %>
18
21
  environment=<%= environment.join(',') %><%
19
22
  end
20
23
  end
21
- %>
24
+ %>
25
+
26
+ [group:<%= app %>]
27
+ programs=<%= app_names.join(',') %>
data/lib/foreman/cli.rb CHANGED
@@ -83,7 +83,11 @@ private ######################################################################
83
83
  end
84
84
 
85
85
  def procfile
86
- options[:procfile] || "Procfile"
86
+ case
87
+ when options[:procfile] then options[:procfile]
88
+ when options[:app_root] then File.expand_path(File.join(options[:app_root], "Procfile"))
89
+ else "Procfile"
90
+ end
87
91
  end
88
92
 
89
93
  def error(message)
@@ -24,8 +24,10 @@ class Foreman::Engine
24
24
  @procfile = Foreman::Procfile.new(procfile)
25
25
  @directory = options[:app_root] || File.expand_path(File.dirname(procfile))
26
26
  @options = options.dup
27
- @environment = read_environment_files(options[:env])
28
27
  @output_mutex = Mutex.new
28
+
29
+ @options[:env] ||= default_env
30
+ @environment = read_environment_files(@options[:env])
29
31
  end
30
32
 
31
33
  def start
@@ -51,6 +53,22 @@ class Foreman::Engine
51
53
  environment.each { |k,v| ENV[k] = v }
52
54
  end
53
55
 
56
+ def self.read_environment(filename)
57
+ return {} unless File.exists?(filename)
58
+
59
+ File.read(filename).split("\n").inject({}) do |hash, line|
60
+ if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
61
+ key, val = [$1, $2]
62
+ case val
63
+ when /\A'(.*)'\z/ then hash[key] = $1
64
+ when /\A"(.*)"\z/ then hash[key] = $1.gsub(/\\(.)/, '\1')
65
+ else hash[key] = val
66
+ end
67
+ end
68
+ hash
69
+ end
70
+ end
71
+
54
72
  private ######################################################################
55
73
 
56
74
  def spawn_processes
@@ -195,26 +213,15 @@ private ######################################################################
195
213
 
196
214
  (filenames || "").split(",").map(&:strip).each do |filename|
197
215
  error "No such file: #{filename}" unless File.exists?(filename)
198
- environment.merge!(read_environment(filename))
216
+ environment.merge!(Foreman::Engine.read_environment(filename))
199
217
  end
200
218
 
201
- environment.merge!(read_environment(".env")) unless filenames
202
219
  environment
203
220
  end
204
221
 
205
- def read_environment(filename)
206
- return {} unless File.exists?(filename)
207
-
208
- File.read(filename).split("\n").inject({}) do |hash, line|
209
- if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
210
- key, val = [$1, $2]
211
- case val
212
- when /\A'(.*)'\z/ then hash[key] = $1
213
- when /\A"(.*)"\z/ then hash[key] = $1.gsub(/\\(.)/, '\1')
214
- else hash[key] = val
215
- end
216
- end
217
- hash
218
- end
222
+ def default_env
223
+ env = File.join(directory, ".env")
224
+ File.exists?(env) ? env : ""
219
225
  end
226
+
220
227
  end
@@ -1,5 +1,5 @@
1
1
  module Foreman
2
2
 
3
- VERSION = "0.41.0"
3
+ VERSION = "0.44.0"
4
4
 
5
5
  end
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" "February 2012" "Foreman 0.39.0" "Foreman Manual"
4
+ .TH "FOREMAN" "1" "April 2012" "Foreman 0.44.0" "Foreman Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBforeman\fR \- manage Procfile\-based applications
@@ -35,6 +35,14 @@ The following options control how the application is run:
35
35
  Specify the number of each process type to run\. The value passed in should be in the format \fBprocess=num,process=num\fR
36
36
  .
37
37
  .TP
38
+ \fB\-e\fR, \fB\-\-env\fR
39
+ Specify one or more \.env files to load
40
+ .
41
+ .TP
42
+ \fB\-f\fR, \fB\-\-procfile\fR
43
+ Specify an alternate Procfile to load, implies \fB\-d\fR at the Procfile root\.
44
+ .
45
+ .TP
38
46
  \fB\-p\fR, \fB\-\-port\fR
39
47
  Specify which port to use as the base for this application\. Should be a multiple of 1000\.
40
48
  .
@@ -34,6 +34,15 @@ describe "Foreman::CLI", :fakefs do
34
34
  subject.start("alpha")
35
35
  end
36
36
  end
37
+
38
+ describe "with an alternate root" do
39
+ it "reads the Procfile from that root" do
40
+ write_procfile "/some/app/Procfile"
41
+ mock(Foreman::Procfile).new("/some/app/Procfile")
42
+ mock.instance_of(Foreman::Engine).start
43
+ foreman %{ start -d /some/app }
44
+ end
45
+ end
37
46
  end
38
47
 
39
48
  describe "export" do
@@ -49,6 +49,14 @@ describe "Foreman::Engine", :fakefs do
49
49
  end
50
50
  end
51
51
 
52
+ describe "directories" do
53
+ it "has the directory default relative to the Procfile" do
54
+ write_procfile "/some/app/Procfile"
55
+ engine = Foreman::Engine.new("/some/app/Procfile")
56
+ engine.directory.should == "/some/app"
57
+ end
58
+ end
59
+
52
60
  describe "environment" do
53
61
  before(:each) do
54
62
  write_procfile
@@ -97,6 +105,15 @@ describe "Foreman::Engine", :fakefs do
97
105
  engine.environment.should == {"FOO"=>"qoo"}
98
106
  engine.start
99
107
  end
108
+
109
+ it "should be loaded relative to the Procfile" do
110
+ FileUtils.mkdir_p "/some/app"
111
+ File.open("/some/app/.env", "w") { |f| f.puts("FOO=qoo") }
112
+ write_procfile "/some/app/Procfile"
113
+ engine = Foreman::Engine.new("/some/app/Procfile")
114
+ engine.environment.should == {"FOO"=>"qoo"}
115
+ engine.start
116
+ end
100
117
  end
101
118
 
102
119
  describe "utf8" do
@@ -15,12 +15,11 @@ describe Foreman::Export::Supervisord, :fakefs do
15
15
  it "exports to the filesystem" do
16
16
  supervisord.export
17
17
 
18
- File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app.conf")
18
+ File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app.conf")
19
19
  end
20
20
 
21
21
  it "cleans up if exporting into an existing dir" do
22
22
  mock(FileUtils).rm("/tmp/init/app.conf")
23
-
24
23
  supervisord.export
25
24
  supervisord.export
26
25
  end
@@ -30,8 +29,7 @@ describe Foreman::Export::Supervisord, :fakefs do
30
29
 
31
30
  it "exports to the filesystem with concurrency" do
32
31
  supervisord.export
33
-
34
- File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app-alpha-2.conf")
32
+ File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app-alpha-2.conf")
35
33
  end
36
34
  end
37
35
 
@@ -46,7 +44,6 @@ describe Foreman::Export::Supervisord, :fakefs do
46
44
 
47
45
  it "can export with alternate template files" do
48
46
  supervisord.export
49
-
50
47
  File.read("/tmp/init/app.conf").should == "alternate_template\n"
51
48
  end
52
49
  end
@@ -67,9 +64,22 @@ describe Foreman::Export::Supervisord, :fakefs do
67
64
 
68
65
  it "can export with alternate template files" do
69
66
  supervisord.export
70
-
71
67
  File.read("/tmp/init/app.conf").should == "default_alternate_template\n"
72
68
  end
73
69
  end
74
70
 
71
+ context "environment export" do
72
+ it "correctly translates environment when exporting" do
73
+ File.open("/tmp/supervisord_env", "w") { |f| f.puts("QUEUE=fastqueue,slowqueue\nVERBOSE=1") }
74
+
75
+ engine = Foreman::Engine.new(procfile,:env => "/tmp/supervisord_env")
76
+ supervisor = Foreman::Export::Supervisord.new("/tmp/init", engine, options)
77
+ stub(supervisor).say
78
+
79
+ supervisor.export
80
+
81
+ File.read("/tmp/init/app.conf").should == example_export_file("supervisord/app-env-with-comma.conf")
82
+ end
83
+ end
84
+
75
85
  end
@@ -8,7 +8,7 @@ stdout_logfile=/var/log/app/alpha-1-out.log
8
8
  stderr_logfile=/var/log/app/alpha-1-err.log
9
9
  user=app
10
10
  directory=/tmp/app
11
- environment=PORT=5000
11
+ environment=PORT="5000"
12
12
  [program:app-alpha-2]
13
13
  command=./alpha
14
14
  autostart=true
@@ -18,4 +18,7 @@ stdout_logfile=/var/log/app/alpha-2-out.log
18
18
  stderr_logfile=/var/log/app/alpha-2-err.log
19
19
  user=app
20
20
  directory=/tmp/app
21
- environment=PORT=5001
21
+ environment=PORT="5001"
22
+
23
+ [group:app]
24
+ programs=app-alpha-1,app-alpha-2
@@ -0,0 +1,24 @@
1
+
2
+ [program:app-alpha]
3
+ command=./alpha
4
+ autostart=true
5
+ autorestart=true
6
+ stopsignal=QUIT
7
+ stdout_logfile=/var/log/app/alpha-1-out.log
8
+ stderr_logfile=/var/log/app/alpha-1-err.log
9
+ user=app
10
+ directory=/tmp/app
11
+ environment=QUEUE="fastqueue,slowqueue",VERBOSE="1",PORT="5000"
12
+ [program:app-bravo]
13
+ command=./bravo
14
+ autostart=true
15
+ autorestart=true
16
+ stopsignal=QUIT
17
+ stdout_logfile=/var/log/app/bravo-1-out.log
18
+ stderr_logfile=/var/log/app/bravo-1-err.log
19
+ user=app
20
+ directory=/tmp/app
21
+ environment=QUEUE="fastqueue,slowqueue",VERBOSE="1",PORT="5100"
22
+
23
+ [group:app]
24
+ programs=app-alpha,app-bravo
@@ -0,0 +1,21 @@
1
+
2
+ [program:app-alpha]
3
+ command=./alpha
4
+ autostart=true
5
+ autorestart=true
6
+ stopsignal=QUIT
7
+ stdout_logfile=/var/log/app/alpha-1-out.log
8
+ stderr_logfile=/var/log/app/alpha-1-err.log
9
+ user=app
10
+ directory=/tmp/app
11
+ environment=FOO="bar",PORT="5000"
12
+ [program:app-bravo]
13
+ command=./bravo
14
+ autostart=true
15
+ autorestart=true
16
+ stopsignal=QUIT
17
+ stdout_logfile=/var/log/app/bravo-1-out.log
18
+ stderr_logfile=/var/log/app/bravo-1-err.log
19
+ user=app
20
+ directory=/tmp/app
21
+ environment=FOO="bar",PORT="5100"
@@ -8,7 +8,7 @@ stdout_logfile=/var/log/app/alpha-1-out.log
8
8
  stderr_logfile=/var/log/app/alpha-1-err.log
9
9
  user=app
10
10
  directory=/tmp/app
11
- environment=PORT=5000
11
+ environment=PORT="5000"
12
12
  [program:app-bravo]
13
13
  command=./bravo
14
14
  autostart=true
@@ -18,4 +18,7 @@ stdout_logfile=/var/log/app/bravo-1-out.log
18
18
  stderr_logfile=/var/log/app/bravo-1-err.log
19
19
  user=app
20
20
  directory=/tmp/app
21
- environment=PORT=5100
21
+ environment=PORT="5100"
22
+
23
+ [group:app]
24
+ programs=app-alpha,app-bravo
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.41.0
4
+ version: 0.44.0
5
5
  prerelease:
6
6
  platform: mingw32
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-16 00:00:00.000000000 Z
12
+ date: 2012-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &70292585295960 !ruby/object:Gem::Requirement
16
+ requirement: &70206771535200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.13.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70292585295960
24
+ version_requirements: *70206771535200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: win32console
27
- requirement: &70292585295160 !ruby/object:Gem::Requirement
27
+ requirement: &70206771534540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.3.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70292585295160
35
+ version_requirements: *70206771534540
36
36
  description: Process manager for applications with multiple components
37
37
  email: ddollar@gmail.com
38
38
  executables:
@@ -100,6 +100,8 @@ files:
100
100
  - spec/resources/export/runit/app-bravo-1-log-run
101
101
  - spec/resources/export/runit/app-bravo-1-run
102
102
  - spec/resources/export/supervisord/app-alpha-2.conf
103
+ - spec/resources/export/supervisord/app-env-with-comma.conf
104
+ - spec/resources/export/supervisord/app-env.conf
103
105
  - spec/resources/export/supervisord/app.conf
104
106
  - spec/resources/export/upstart/app-alpha-1.conf
105
107
  - spec/resources/export/upstart/app-alpha-2.conf