HeSYINUvSBZfxqA-foreman 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,89 @@
1
+ require "spec_helper"
2
+ require "foreman/engine"
3
+
4
+ describe "Foreman::Engine" 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.processes["alpha"].command.should == "./alpha"
19
+ subject.processes["bravo"].command.should == "./bravo"
20
+ end
21
+ end
22
+
23
+ describe "with a deprecated Procfile" do
24
+ before do
25
+ File.open("Procfile", "w") do |file|
26
+ file.puts "name command"
27
+ end
28
+ end
29
+
30
+ it "should print a deprecation warning" do
31
+ mock(subject).warn_deprecated_procfile!
32
+ subject.processes.length.should == 1
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "start" do
38
+ it "forks the processes" do
39
+ write_procfile
40
+ mock(subject).fork(subject.processes["alpha"], {}, {})
41
+ mock(subject).fork(subject.processes["bravo"], {}, {})
42
+ mock(subject).watch_for_termination
43
+ subject.start
44
+ end
45
+
46
+ it "handles concurrency" do
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, {})
51
+ mock(subject).watch_for_termination
52
+ subject.start(:concurrency => "alpha=2")
53
+ end
54
+ end
55
+
56
+ describe "execute" do
57
+ it "runs the processes" do
58
+ write_procfile
59
+ mock(subject).fork(subject.processes["alpha"], {}, {})
60
+ mock(subject).watch_for_termination
61
+ subject.execute("alpha")
62
+ end
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
89
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+ require "foreman/engine"
3
+ require "foreman/export/upstart"
4
+ require "tmpdir"
5
+
6
+ describe Foreman::Export::Upstart do
7
+ let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
+ let(:engine) { Foreman::Engine.new(procfile) }
9
+ let(:upstart) { Foreman::Export::Upstart.new(engine) }
10
+
11
+ before(:each) { load_export_templates_into_fakefs("upstart") }
12
+ before(:each) { stub(upstart).say }
13
+
14
+ it "exports to the filesystem" do
15
+ upstart.export("/tmp/init")
16
+
17
+ File.read("/tmp/init/app.conf").should == example_export_file("upstart/app.conf")
18
+ File.read("/tmp/init/app-alpha.conf").should == example_export_file("upstart/app-alpha.conf")
19
+ File.read("/tmp/init/app-alpha-1.conf").should == example_export_file("upstart/app-alpha-1.conf")
20
+ File.read("/tmp/init/app-alpha-2.conf").should == example_export_file("upstart/app-alpha-2.conf")
21
+ File.read("/tmp/init/app-bravo.conf").should == example_export_file("upstart/app-bravo.conf")
22
+ File.read("/tmp/init/app-bravo-1.conf").should == example_export_file("upstart/app-bravo-1.conf")
23
+ end
24
+
25
+ context "with alternate templates" do
26
+ let(:template_root) { "/tmp/alternate" }
27
+
28
+ before do
29
+ FileUtils.mkdir_p template_root
30
+ File.open("#{template_root}/master.conf.erb", "w") { |f| f.puts "alternate_template" }
31
+ end
32
+
33
+ it "can export with alternate template files" do
34
+ upstart.export("/tmp/init", :template => template_root)
35
+
36
+ File.read("/tmp/init/app.conf").should == "alternate_template\n"
37
+ end
38
+ end
39
+
40
+ context "with alternate templates from home dir" do
41
+ let(:default_template_root) {File.expand_path("~/.foreman/templates")}
42
+
43
+ before do
44
+ FileUtils.mkdir_p default_template_root
45
+ File.open("#{default_template_root}/master.conf.erb", "w") { |f| f.puts "default_alternate_template" }
46
+ end
47
+
48
+ it "can export with alternate template files" do
49
+ upstart.export("/tmp/init")
50
+
51
+ File.read("/tmp/init/app.conf").should == "default_alternate_template\n"
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,2 @@
1
+ require "spec_helper"
2
+ require "foreman/export"
@@ -0,0 +1,2 @@
1
+ require "spec_helper"
2
+ require "foreman/process"
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+ require "foreman"
3
+
4
+ describe Foreman do
5
+
6
+ describe "VERSION" do
7
+ subject { Foreman::VERSION }
8
+ it { should be_a String }
9
+ end
10
+
11
+ end
@@ -0,0 +1,5 @@
1
+ start on starting app-alpha
2
+ stop on stopping app-alpha
3
+ respawn
4
+
5
+ exec su - app -c 'cd /tmp/app; export PORT=5000; ./alpha >> /var/log/app/alpha-1.log 2>&1'
@@ -0,0 +1,5 @@
1
+ start on starting app-alpha
2
+ stop on stopping app-alpha
3
+ respawn
4
+
5
+ exec su - app -c 'cd /tmp/app; export PORT=5001; ./alpha >> /var/log/app/alpha-2.log 2>&1'
@@ -0,0 +1,2 @@
1
+ start on starting app
2
+ stop on stopping app
@@ -0,0 +1,5 @@
1
+ start on starting app-bravo
2
+ stop on stopping app-bravo
3
+ respawn
4
+
5
+ exec su - app -c 'cd /tmp/app; export PORT=5100; ./bravo >> /var/log/app/bravo-1.log 2>&1'
@@ -0,0 +1,2 @@
1
+ start on starting app
2
+ stop on stopping app
@@ -0,0 +1,8 @@
1
+ pre-start script
2
+
3
+ bash << "EOF"
4
+ mkdir -p /var/log/app
5
+ chown -R app /var/log/app
6
+ EOF
7
+
8
+ end script
@@ -0,0 +1,60 @@
1
+ require "rubygems"
2
+ require "rspec"
3
+ require "fakefs/safe"
4
+ require "fakefs/spec_helpers"
5
+
6
+ $:.unshift File.expand_path("../../lib", __FILE__)
7
+
8
+ def mock_error(subject, message)
9
+ mock_exit do
10
+ mock(subject).puts("ERROR: #{message}")
11
+ yield
12
+ end
13
+ end
14
+
15
+ def mock_exit(&block)
16
+ block.should raise_error(SystemExit)
17
+ end
18
+
19
+ def write_foreman_config(app)
20
+ File.open("/etc/foreman/#{app}.conf", "w") do |file|
21
+ file.puts %{#{app}_processes="alpha bravo"}
22
+ file.puts %{#{app}_alpha="1"}
23
+ file.puts %{#{app}_bravo="2"}
24
+ end
25
+ end
26
+
27
+ def write_procfile(procfile="Procfile")
28
+ File.open(procfile, "w") do |file|
29
+ file.puts "alpha: ./alpha"
30
+ file.puts "\n"
31
+ file.puts "bravo: ./bravo"
32
+ end
33
+ File.expand_path(procfile)
34
+ end
35
+
36
+ def load_export_templates_into_fakefs(type)
37
+ FakeFS.deactivate!
38
+ files = Dir[File.expand_path("../../data/export/#{type}/**", __FILE__)].inject({}) do |hash, file|
39
+ hash.update(file => File.read(file))
40
+ end
41
+ FakeFS.activate!
42
+ files.each do |filename, contents|
43
+ File.open(filename, "w") do |f|
44
+ f.puts contents
45
+ end
46
+ end
47
+ end
48
+
49
+ def example_export_file(filename)
50
+ FakeFS.deactivate!
51
+ data = File.read(File.expand_path("../resources/export/#{filename}", __FILE__))
52
+ FakeFS.activate!
53
+ data
54
+ end
55
+
56
+ RSpec.configure do |config|
57
+ config.color_enabled = true
58
+ config.include FakeFS::SpecHelpers
59
+ config.mock_with :rr
60
+ end
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: HeSYINUvSBZfxqA-foreman
3
+ version: !ruby/object:Gem::Version
4
+ hash: 79
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 20
9
+ - 0
10
+ version: 0.20.0
11
+ platform: ruby
12
+ authors:
13
+ - David Dollar
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-02 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: term-ansicolor
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 29
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 5
34
+ version: 1.0.5
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: thor
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 39
46
+ segments:
47
+ - 0
48
+ - 13
49
+ - 6
50
+ version: 0.13.6
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: parka
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: ronn
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: fakefs
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ hash: 21
104
+ segments:
105
+ - 0
106
+ - 2
107
+ - 1
108
+ version: 0.2.1
109
+ type: :development
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ name: rcov
113
+ prerelease: false
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ hash: 43
120
+ segments:
121
+ - 0
122
+ - 9
123
+ - 8
124
+ version: 0.9.8
125
+ type: :development
126
+ version_requirements: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ name: rr
129
+ prerelease: false
130
+ requirement: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ~>
134
+ - !ruby/object:Gem::Version
135
+ hash: 19
136
+ segments:
137
+ - 1
138
+ - 0
139
+ - 2
140
+ version: 1.0.2
141
+ type: :development
142
+ version_requirements: *id008
143
+ - !ruby/object:Gem::Dependency
144
+ name: rspec
145
+ prerelease: false
146
+ requirement: &id009 !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ~>
150
+ - !ruby/object:Gem::Version
151
+ hash: 23
152
+ segments:
153
+ - 2
154
+ - 6
155
+ - 0
156
+ version: 2.6.0
157
+ type: :development
158
+ version_requirements: *id009
159
+ description: Process manager for applications with multiple components
160
+ email: ddollar@gmail.com
161
+ executables:
162
+ - foreman
163
+ extensions: []
164
+
165
+ extra_rdoc_files: []
166
+
167
+ files:
168
+ - bin/foreman
169
+ - bin/foreman-runner
170
+ - data/example/error
171
+ - data/example/log/neverdie.log
172
+ - data/example/Procfile
173
+ - data/example/Procfile.without_colon
174
+ - data/example/ticker
175
+ - data/export/upstart/master.conf.erb
176
+ - data/export/upstart/process.conf.erb
177
+ - data/export/upstart/process_master.conf.erb
178
+ - lib/foreman/cli.rb
179
+ - lib/foreman/engine.rb
180
+ - lib/foreman/export/base.rb
181
+ - lib/foreman/export/inittab.rb
182
+ - lib/foreman/export/upstart.rb
183
+ - lib/foreman/export.rb
184
+ - lib/foreman/process.rb
185
+ - lib/foreman/utils.rb
186
+ - lib/foreman/version.rb
187
+ - lib/foreman.rb
188
+ - README.markdown
189
+ - spec/foreman/cli_spec.rb
190
+ - spec/foreman/engine_spec.rb
191
+ - spec/foreman/export/upstart_spec.rb
192
+ - spec/foreman/export_spec.rb
193
+ - spec/foreman/process_spec.rb
194
+ - spec/foreman_spec.rb
195
+ - spec/resources/export/upstart/app-alpha-1.conf
196
+ - spec/resources/export/upstart/app-alpha-2.conf
197
+ - spec/resources/export/upstart/app-alpha.conf
198
+ - spec/resources/export/upstart/app-bravo-1.conf
199
+ - spec/resources/export/upstart/app-bravo.conf
200
+ - spec/resources/export/upstart/app.conf
201
+ - spec/spec_helper.rb
202
+ - man/foreman.1
203
+ has_rdoc: true
204
+ homepage: http://github.com/ddollar/foreman
205
+ licenses: []
206
+
207
+ post_install_message:
208
+ rdoc_options: []
209
+
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ none: false
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ hash: 3
218
+ segments:
219
+ - 0
220
+ version: "0"
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ none: false
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ hash: 3
227
+ segments:
228
+ - 0
229
+ version: "0"
230
+ requirements: []
231
+
232
+ rubyforge_project:
233
+ rubygems_version: 1.5.3
234
+ signing_key:
235
+ specification_version: 3
236
+ summary: Process manager for applications with multiple components
237
+ test_files: []
238
+