foreman 0.37.0-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/README.md +39 -0
  2. data/bin/foreman +7 -0
  3. data/bin/runner +36 -0
  4. data/data/example/Procfile +2 -0
  5. data/data/example/Procfile.without_colon +2 -0
  6. data/data/example/error +7 -0
  7. data/data/example/log/neverdie.log +4 -0
  8. data/data/example/ticker +14 -0
  9. data/data/export/bluepill/master.pill.erb +27 -0
  10. data/data/export/runit/log_run.erb +7 -0
  11. data/data/export/runit/run.erb +3 -0
  12. data/data/export/upstart/master.conf.erb +8 -0
  13. data/data/export/upstart/process.conf.erb +5 -0
  14. data/data/export/upstart/process_master.conf.erb +2 -0
  15. data/lib/foreman.rb +25 -0
  16. data/lib/foreman/cli.rb +98 -0
  17. data/lib/foreman/distribution.rb +9 -0
  18. data/lib/foreman/engine.rb +234 -0
  19. data/lib/foreman/export.rb +32 -0
  20. data/lib/foreman/export/base.rb +51 -0
  21. data/lib/foreman/export/bluepill.rb +26 -0
  22. data/lib/foreman/export/inittab.rb +36 -0
  23. data/lib/foreman/export/runit.rb +59 -0
  24. data/lib/foreman/export/upstart.rb +41 -0
  25. data/lib/foreman/helpers.rb +45 -0
  26. data/lib/foreman/process.rb +96 -0
  27. data/lib/foreman/procfile.rb +38 -0
  28. data/lib/foreman/procfile_entry.rb +22 -0
  29. data/lib/foreman/utils.rb +18 -0
  30. data/lib/foreman/version.rb +5 -0
  31. data/man/foreman.1 +222 -0
  32. data/spec/foreman/cli_spec.rb +163 -0
  33. data/spec/foreman/engine_spec.rb +86 -0
  34. data/spec/foreman/export/base_spec.rb +22 -0
  35. data/spec/foreman/export/bluepill_spec.rb +36 -0
  36. data/spec/foreman/export/inittab_spec.rb +40 -0
  37. data/spec/foreman/export/runit_spec.rb +41 -0
  38. data/spec/foreman/export/upstart_spec.rb +87 -0
  39. data/spec/foreman/export_spec.rb +24 -0
  40. data/spec/foreman/helpers_spec.rb +26 -0
  41. data/spec/foreman/process_spec.rb +131 -0
  42. data/spec/foreman_spec.rb +34 -0
  43. data/spec/helper_spec.rb +18 -0
  44. data/spec/resources/export/bluepill/app-concurrency.pill +47 -0
  45. data/spec/resources/export/bluepill/app.pill +44 -0
  46. data/spec/resources/export/inittab/inittab.concurrency +4 -0
  47. data/spec/resources/export/inittab/inittab.default +4 -0
  48. data/spec/resources/export/runit/app-alpha-1-log-run +7 -0
  49. data/spec/resources/export/runit/app-alpha-1-run +3 -0
  50. data/spec/resources/export/runit/app-alpha-2-log-run +7 -0
  51. data/spec/resources/export/runit/app-alpha-2-run +3 -0
  52. data/spec/resources/export/runit/app-bravo-1-log-run +7 -0
  53. data/spec/resources/export/runit/app-bravo-1-run +3 -0
  54. data/spec/resources/export/upstart/app-alpha-1.conf +5 -0
  55. data/spec/resources/export/upstart/app-alpha-2.conf +5 -0
  56. data/spec/resources/export/upstart/app-alpha.conf +2 -0
  57. data/spec/resources/export/upstart/app-bravo-1.conf +5 -0
  58. data/spec/resources/export/upstart/app-bravo.conf +2 -0
  59. data/spec/resources/export/upstart/app.conf +8 -0
  60. data/spec/spec_helper.rb +98 -0
  61. metadata +138 -0
@@ -0,0 +1,18 @@
1
+ require "foreman"
2
+
3
+ class Foreman::Utils
4
+
5
+ def self.parse_concurrency(concurrency)
6
+ begin
7
+ pairs = concurrency.to_s.gsub(/\s/, "").split(",")
8
+
9
+ default = concurrency.nil? ? 1 : 0
10
+
11
+ pairs.inject(Hash.new(default)) do |hash, pair|
12
+ process, amount = pair.split("=")
13
+ hash.update(process => amount.to_i)
14
+ end
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,5 @@
1
+ module Foreman
2
+
3
+ VERSION = "0.37.0"
4
+
5
+ end
data/man/foreman.1 ADDED
@@ -0,0 +1,222 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "FOREMAN" "1" "January 2012" "Foreman 0.33.1" "Foreman Manual"
5
+ .
6
+ .SH "NAME"
7
+ \fBforeman\fR \- manage Procfile\-based applications
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBforeman start [process]\fR
11
+ .
12
+ .br
13
+ \fBforeman export <format> [location]\fR
14
+ .
15
+ .SH "DESCRIPTION"
16
+ \fBForeman\fR is a manager for Procfile\-based applications\. Its aim is to abstract away the details of the Procfile format, and allow you to either run your application directly or export it to some other process management format\.
17
+ .
18
+ .SH "RUNNING"
19
+ \fBforeman start\fR is used to run your application directly from the command line\.
20
+ .
21
+ .P
22
+ If no additional parameters are passed, foreman will run one instance of each type of process defined in your Procfile\.
23
+ .
24
+ .P
25
+ If a parameter is passed, foreman will run one instance of the specified application type\.
26
+ .
27
+ .P
28
+ The following options control how the application is run:
29
+ .
30
+ .TP
31
+ \fB\-c\fR, \fB\-\-concurrency\fR
32
+ Specify the number of each process type to run\. The value passed in should be in the format \fBprocess=num,process=num\fR
33
+ .
34
+ .TP
35
+ \fB\-p\fR, \fB\-\-port\fR
36
+ Specify which port to use as the base for this application\. Should be a multiple of 1000\.
37
+ .
38
+ .SH "EXPORTING"
39
+ \fBforeman export\fR is used to export your application to another process management format\.
40
+ .
41
+ .P
42
+ An location to export can be passed as an argument\. This argument may be either required or optional depending on the export format\.
43
+ .
44
+ .P
45
+ The following options control how the application is run:
46
+ .
47
+ .TP
48
+ \fB\-a\fR, \fB\-\-app\fR
49
+ Use this name rather than the application\'s root directory name as the name of the application when exporting\.
50
+ .
51
+ .TP
52
+ \fB\-c\fR, \fB\-\-concurrency\fR
53
+ Specify the number of each process type to run\. The value passed in should be in the format \fBprocess=num,process=num\fR
54
+ .
55
+ .TP
56
+ \fB\-l\fR, \fB\-\-log\fR
57
+ Specify the directory to place process logs in\.
58
+ .
59
+ .TP
60
+ \fB\-p\fR, \fB\-\-port\fR
61
+ Specify which port to use as the base for this application\. Should be a multiple of 1000\.
62
+ .
63
+ .TP
64
+ \fB\-u\fR, \fB\-\-user\fR
65
+ Specify the user the application should be run as\. Defaults to the app name
66
+ .
67
+ .SH "OPTIONS"
68
+ These options control all modes of foreman\'s operation\.
69
+ .
70
+ .TP
71
+ \fB\-d\fR, \fB\-\-directory\fR
72
+ Specify an alternate application root\. This defaults to the directory containing the Procfile\.
73
+ .
74
+ .TP
75
+ \fB\-e\fR, \fB\-\-env\fR
76
+ Specify an alternate environment file\. You can specify more than one file by using: \fB\-\-env file1,file2\fR\.
77
+ .
78
+ .TP
79
+ \fB\-f\fR, \fB\-\-procfile\fR
80
+ 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\.
81
+ .
82
+ .SH "EXPORT FORMATS"
83
+ foreman currently supports the following output formats:
84
+ .
85
+ .IP "\(bu" 4
86
+ bluepill
87
+ .
88
+ .IP "\(bu" 4
89
+ inittab
90
+ .
91
+ .IP "\(bu" 4
92
+ runit
93
+ .
94
+ .IP "\(bu" 4
95
+ upstart
96
+ .
97
+ .IP "" 0
98
+ .
99
+ .SH "INITTAB EXPORT"
100
+ Will export a chunk of inittab\-compatible configuration:
101
+ .
102
+ .IP "" 4
103
+ .
104
+ .nf
105
+
106
+ # \-\-\-\-\- foreman example processes \-\-\-\-\-
107
+ EX01:4:respawn:/bin/su \- example \-c \'PORT=5000 bundle exec thin start >> /var/log/web\-1\.log 2>&1\'
108
+ EX02:4:respawn:/bin/su \- example \-c \'PORT=5100 bundle exec rake jobs:work >> /var/log/job\-1\.log 2>&1\'
109
+ # \-\-\-\-\- end foreman example processes \-\-\-\-\-
110
+ .
111
+ .fi
112
+ .
113
+ .IP "" 0
114
+ .
115
+ .SH "UPSTART EXPORT"
116
+ Will create a series of upstart scripts in the location you specify\. Scripts will be structured to make the following commands valid:
117
+ .
118
+ .P
119
+ \fBstart appname\fR
120
+ .
121
+ .P
122
+ \fBstop appname\-processname\fR
123
+ .
124
+ .P
125
+ \fBrestart appname\-processname\-3\fR
126
+ .
127
+ .SH "PROCFILE"
128
+ A Procfile should contain both a name for the process and the command used to run it\.
129
+ .
130
+ .IP "" 4
131
+ .
132
+ .nf
133
+
134
+ web: bundle exec thin start
135
+ job: bundle exec rake jobs:work
136
+ .
137
+ .fi
138
+ .
139
+ .IP "" 0
140
+ .
141
+ .P
142
+ A process name may contain letters, numbers amd the underscore character\. You can validate your Procfile format using the \fBcheck\fR command:
143
+ .
144
+ .IP "" 4
145
+ .
146
+ .nf
147
+
148
+ $ foreman check
149
+ .
150
+ .fi
151
+ .
152
+ .IP "" 0
153
+ .
154
+ .SH "ENVIRONMENT"
155
+ If a \fB\.env\fR file exists in the current directory, the default environment will be read from it\. This file should contain key/value pairs, separated by \fB=\fR, with one key/value pair per line\.
156
+ .
157
+ .IP "" 4
158
+ .
159
+ .nf
160
+
161
+ FOO=bar
162
+ BAZ=qux
163
+ .
164
+ .fi
165
+ .
166
+ .IP "" 0
167
+ .
168
+ .SH "DEFAULT OPTIONS"
169
+ If a \fB\.foreman\fR file exists in the current directory, default options will be read from it\. This file should be in YAML format with the long option name as keys\. Example:
170
+ .
171
+ .IP "" 4
172
+ .
173
+ .nf
174
+
175
+ concurrency: alpha=0,bravo=1
176
+ port: 15000
177
+ .
178
+ .fi
179
+ .
180
+ .IP "" 0
181
+ .
182
+ .SH "EXAMPLES"
183
+ Start one instance of each process type, interleave the output on stdout:
184
+ .
185
+ .IP "" 4
186
+ .
187
+ .nf
188
+
189
+ $ foreman start
190
+ .
191
+ .fi
192
+ .
193
+ .IP "" 0
194
+ .
195
+ .P
196
+ Export the application in upstart format:
197
+ .
198
+ .IP "" 4
199
+ .
200
+ .nf
201
+
202
+ $ foreman export upstart /etc/init
203
+ .
204
+ .fi
205
+ .
206
+ .IP "" 0
207
+ .
208
+ .P
209
+ Run one process type from the application defined in a specific Procfile:
210
+ .
211
+ .IP "" 4
212
+ .
213
+ .nf
214
+
215
+ $ foreman start alpha \-p ~/myapp/Procfile
216
+ .
217
+ .fi
218
+ .
219
+ .IP "" 0
220
+ .
221
+ .SH "COPYRIGHT"
222
+ Foreman is Copyright (C) 2010 David Dollar \fIhttp://daviddollar\.org\fR
@@ -0,0 +1,163 @@
1
+ require "spec_helper"
2
+ require "foreman/cli"
3
+
4
+ describe "Foreman::CLI", :fakefs do
5
+ subject { Foreman::CLI.new }
6
+
7
+ describe "start" do
8
+ describe "with a non-existent Procfile" do
9
+ it "prints an error" do
10
+ mock_error(subject, "Procfile does not exist.") do
11
+ dont_allow.instance_of(Foreman::Engine).start
12
+ subject.start
13
+ end
14
+ end
15
+ end
16
+
17
+ describe "with a Procfile" do
18
+ before(:each) { write_procfile }
19
+
20
+ it "runs successfully" do
21
+ dont_allow(subject).error
22
+ mock.instance_of(Foreman::Engine).start
23
+ subject.start
24
+ end
25
+ end
26
+ end
27
+
28
+ describe "export" do
29
+ describe "options" do
30
+ it "uses .foreman" do
31
+ write_procfile
32
+ File.open(".foreman", "w") { |f| f.puts "concurrency: alpha=2" }
33
+ mock_export = mock(Foreman::Export::Upstart)
34
+ mock(Foreman::Export::Upstart).new("/upstart", is_a(Foreman::Engine), { "concurrency" => "alpha=2" }) { mock_export }
35
+ mock_export.export
36
+ foreman %{ export upstart /upstart }
37
+ end
38
+
39
+ it "respects --env" do
40
+ write_procfile
41
+ write_env("envfile")
42
+ mock_export = mock(Foreman::Export::Upstart)
43
+ mock(Foreman::Export::Upstart).new("/upstart", is_a(Foreman::Engine), { "env" => "envfile" }) { mock_export }
44
+ mock_export.export
45
+ foreman %{ export upstart /upstart --env envfile }
46
+ end
47
+ end
48
+
49
+ describe "with a non-existent Procfile" do
50
+ it "prints an error" do
51
+ mock_error(subject, "Procfile does not exist.") do
52
+ dont_allow.instance_of(Foreman::Engine).export
53
+ subject.export("testapp")
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "with a Procfile" do
59
+ before(:each) { write_procfile }
60
+
61
+ describe "with a formatter with a generic error" do
62
+ before do
63
+ mock(Foreman::Export).formatter("errorful") { Class.new(Foreman::Export::Base) do
64
+ def export
65
+ raise Foreman::Export::Exception.new("foo")
66
+ end
67
+ end }
68
+ end
69
+
70
+ it "prints an error" do
71
+ mock_error(subject, "foo") do
72
+ subject.export("errorful")
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "with a valid config" do
78
+ before(:each) { write_foreman_config("testapp") }
79
+
80
+ it "runs successfully" do
81
+ dont_allow(subject).error
82
+ mock_export = mock(Foreman::Export::Upstart)
83
+ mock(Foreman::Export::Upstart).new("/tmp/foo", is_a(Foreman::Engine), {}) { mock_export }
84
+ mock_export.export
85
+ subject.export("upstart", "/tmp/foo")
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "check" do
92
+ describe "with a valid Procfile" do
93
+ before { write_procfile }
94
+
95
+ it "displays the jobs" do
96
+ mock(subject).puts("valid procfile detected (alpha, bravo)")
97
+ subject.check
98
+ end
99
+ end
100
+
101
+ describe "with a blank Procfile" do
102
+ before do
103
+ FileUtils.touch("Procfile")
104
+ end
105
+
106
+ it "displays an error" do
107
+ mock_error(subject, "no processes defined") do
108
+ subject.check
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ describe "run" do
115
+ describe "with a valid Procfile" do
116
+ before { write_procfile }
117
+
118
+ describe "and a command" do
119
+ let(:command) { ["ls", "-l"] }
120
+
121
+ before(:each) do
122
+ stub(subject).exec
123
+ end
124
+
125
+ it "should load the environment file" do
126
+ write_env
127
+ preserving_env do
128
+ subject.run *command
129
+ ENV["FOO"].should == "bar"
130
+ end
131
+
132
+ ENV["FOO"].should be_nil
133
+ end
134
+
135
+ it "should runute the command as a string" do
136
+ mock(subject).exec(command.join(" "))
137
+ subject.run *command
138
+ end
139
+ end
140
+
141
+ describe "and a non-existent command" do
142
+ let(:command) { "iuhtngrglhulhdfg" }
143
+
144
+ it "should print an error" do
145
+ mock_error(subject, "command not found: #{command}") do
146
+ subject.run command
147
+ end
148
+ end
149
+ end
150
+
151
+ describe "and a non-executable command" do
152
+ let(:command) { __FILE__ }
153
+
154
+ it "should print an error" do
155
+ mock_error(subject, "not executable: #{command}") do
156
+ subject.run command
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ end
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+ require "foreman/engine"
3
+
4
+ describe "Foreman::Engine", :fakefs do
5
+ subject { Foreman::Engine.new("Procfile", {}) }
6
+
7
+ describe "initialize" do
8
+ describe "without an existing Procfile" do
9
+ it "raises an error" do
10
+ lambda { subject }.should raise_error
11
+ end
12
+ end
13
+
14
+ describe "with a Procfile" do
15
+ before { write_procfile }
16
+
17
+ it "reads the processes" do
18
+ subject.procfile["alpha"].command.should == "./alpha"
19
+ subject.procfile["bravo"].command.should == "./bravo"
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "start" do
25
+ it "forks the processes" do
26
+ write_procfile
27
+ mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./alpha", is_a(IO))
28
+ mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./bravo", is_a(IO))
29
+ mock(subject).watch_for_output
30
+ mock(subject).watch_for_termination
31
+ subject.start
32
+ end
33
+
34
+ it "handles concurrency" do
35
+ write_procfile
36
+ engine = Foreman::Engine.new("Procfile",:concurrency => "alpha=2")
37
+ mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./alpha", is_a(IO)).twice
38
+ mock.instance_of(Foreman::Process).run_process(Dir.pwd, "./bravo", is_a(IO)).never
39
+ mock(engine).watch_for_output
40
+ mock(engine).watch_for_termination
41
+ engine.start
42
+ end
43
+ end
44
+
45
+ describe "environment" do
46
+ before(:each) do
47
+ write_procfile
48
+ stub(Process).fork
49
+ end
50
+
51
+ it "should read if specified" do
52
+ File.open("/tmp/env", "w") { |f| f.puts("FOO=baz") }
53
+ engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
54
+ stub(engine).info
55
+ mock(engine).spawn_processes
56
+ mock(engine).watch_for_termination
57
+ engine.environment.should == {"FOO"=>"baz"}
58
+ engine.start
59
+ end
60
+
61
+ it "should read more than one if specified" do
62
+ File.open("/tmp/env1", "w") { |f| f.puts("FOO=bar") }
63
+ File.open("/tmp/env2", "w") { |f| f.puts("BAZ=qux") }
64
+ engine = Foreman::Engine.new("Procfile", :env => "/tmp/env1,/tmp/env2")
65
+ stub(engine).info
66
+ mock(engine).spawn_processes
67
+ mock(engine).watch_for_termination
68
+ engine.environment.should == { "FOO"=>"bar", "BAZ"=>"qux" }
69
+ engine.start
70
+ end
71
+
72
+ it "should fail if specified and doesnt exist" do
73
+ mock.instance_of(Foreman::Engine).error("No such file: /tmp/env")
74
+ engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")
75
+ end
76
+
77
+ it "should read .env if none specified" do
78
+ File.open(".env", "w") { |f| f.puts("FOO=qoo") }
79
+ engine = Foreman::Engine.new("Procfile")
80
+ mock(engine).spawn_processes
81
+ mock(engine).watch_for_termination
82
+ engine.environment.should == {"FOO"=>"qoo"}
83
+ engine.start
84
+ end
85
+ end
86
+ end