foreman 0.50.0-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +46 -0
- data/bin/foreman +7 -0
- data/bin/foreman-runner +32 -0
- data/bin/taskman +8 -0
- data/data/example/Procfile +4 -0
- data/data/example/Procfile.without_colon +2 -0
- data/data/example/error +7 -0
- data/data/example/log/neverdie.log +4 -0
- data/data/example/spawnee +14 -0
- data/data/example/spawner +7 -0
- data/data/example/ticker +14 -0
- data/data/example/utf8 +11 -0
- data/data/export/bluepill/master.pill.erb +28 -0
- data/data/export/launchd/launchd.plist.erb +22 -0
- data/data/export/runit/log/run.erb +7 -0
- data/data/export/runit/run.erb +3 -0
- data/data/export/supervisord/app.conf.erb +27 -0
- data/data/export/upstart/master.conf.erb +8 -0
- data/data/export/upstart/process.conf.erb +5 -0
- data/data/export/upstart/process_master.conf.erb +2 -0
- data/lib/foreman.rb +23 -0
- data/lib/foreman/cli.rb +140 -0
- data/lib/foreman/distribution.rb +9 -0
- data/lib/foreman/engine.rb +313 -0
- data/lib/foreman/engine/cli.rb +105 -0
- data/lib/foreman/env.rb +27 -0
- data/lib/foreman/export.rb +34 -0
- data/lib/foreman/export/base.rb +146 -0
- data/lib/foreman/export/bluepill.rb +12 -0
- data/lib/foreman/export/inittab.rb +33 -0
- data/lib/foreman/export/launchd.rb +15 -0
- data/lib/foreman/export/runit.rb +34 -0
- data/lib/foreman/export/supervisord.rb +16 -0
- data/lib/foreman/export/upstart.rb +25 -0
- data/lib/foreman/helpers.rb +45 -0
- data/lib/foreman/process.rb +102 -0
- data/lib/foreman/procfile.rb +92 -0
- data/lib/foreman/version.rb +5 -0
- data/man/foreman.1 +244 -0
- data/spec/foreman/cli_spec.rb +87 -0
- data/spec/foreman/engine_spec.rb +104 -0
- data/spec/foreman/export/base_spec.rb +19 -0
- data/spec/foreman/export/bluepill_spec.rb +37 -0
- data/spec/foreman/export/inittab_spec.rb +40 -0
- data/spec/foreman/export/launchd_spec.rb +21 -0
- data/spec/foreman/export/runit_spec.rb +36 -0
- data/spec/foreman/export/supervisord_spec.rb +36 -0
- data/spec/foreman/export/upstart_spec.rb +88 -0
- data/spec/foreman/export_spec.rb +24 -0
- data/spec/foreman/helpers_spec.rb +26 -0
- data/spec/foreman/process_spec.rb +48 -0
- data/spec/foreman/procfile_spec.rb +41 -0
- data/spec/foreman_spec.rb +16 -0
- data/spec/helper_spec.rb +18 -0
- data/spec/resources/Procfile +4 -0
- data/spec/resources/bin/echo +2 -0
- data/spec/resources/bin/env +2 -0
- data/spec/resources/bin/test +2 -0
- data/spec/resources/bin/utf8 +2 -0
- data/spec/resources/export/bluepill/app-concurrency.pill +49 -0
- data/spec/resources/export/bluepill/app.pill +46 -0
- data/spec/resources/export/inittab/inittab.concurrency +4 -0
- data/spec/resources/export/inittab/inittab.default +4 -0
- data/spec/resources/export/launchd/launchd-a.default +22 -0
- data/spec/resources/export/launchd/launchd-b.default +22 -0
- data/spec/resources/export/runit/app-alpha-1/log/run +7 -0
- data/spec/resources/export/runit/app-alpha-1/run +3 -0
- data/spec/resources/export/runit/app-alpha-2/log/run +7 -0
- data/spec/resources/export/runit/app-alpha-2/run +3 -0
- data/spec/resources/export/runit/app-bravo-1/log/run +7 -0
- data/spec/resources/export/runit/app-bravo-1/run +3 -0
- data/spec/resources/export/supervisord/app-alpha-1.conf +24 -0
- data/spec/resources/export/supervisord/app-alpha-2.conf +24 -0
- data/spec/resources/export/upstart/app-alpha-1.conf +5 -0
- data/spec/resources/export/upstart/app-alpha-2.conf +5 -0
- data/spec/resources/export/upstart/app-alpha.conf +2 -0
- data/spec/resources/export/upstart/app-bravo-1.conf +5 -0
- data/spec/resources/export/upstart/app-bravo.conf +2 -0
- data/spec/resources/export/upstart/app.conf +8 -0
- data/spec/spec_helper.rb +153 -0
- metadata +148 -0
data/spec/helper_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "spec helpers" do
|
4
|
+
describe "#preserving_env" do
|
5
|
+
after { ENV.delete "FOO" }
|
6
|
+
|
7
|
+
it "should remove added environment vars" do
|
8
|
+
preserving_env { ENV["FOO"] = "baz" }
|
9
|
+
ENV["FOO"].should == nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should reset modified environment vars" do
|
13
|
+
ENV["FOO"] = "bar"
|
14
|
+
preserving_env { ENV["FOO"] = "baz"}
|
15
|
+
ENV["FOO"].should == "bar"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepill.log") do |app|
|
2
|
+
|
3
|
+
app.uid = "app"
|
4
|
+
app.gid = "app"
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
app.process("alpha-1") do |process|
|
10
|
+
process.start_command = "./alpha"
|
11
|
+
|
12
|
+
process.working_dir = "/tmp/app"
|
13
|
+
process.daemonize = true
|
14
|
+
process.environment = {"PORT"=>"5000"}
|
15
|
+
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
|
16
|
+
process.stop_grace_time = 45.seconds
|
17
|
+
|
18
|
+
process.stdout = process.stderr = "/var/log/app/app-alpha-1.log"
|
19
|
+
|
20
|
+
process.monitor_children do |children|
|
21
|
+
children.stop_command "kill {{PID}}"
|
22
|
+
end
|
23
|
+
|
24
|
+
process.group = "app-alpha"
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
app.process("alpha-2") do |process|
|
29
|
+
process.start_command = "./alpha"
|
30
|
+
|
31
|
+
process.working_dir = "/tmp/app"
|
32
|
+
process.daemonize = true
|
33
|
+
process.environment = {"PORT"=>"5001"}
|
34
|
+
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
|
35
|
+
process.stop_grace_time = 45.seconds
|
36
|
+
|
37
|
+
process.stdout = process.stderr = "/var/log/app/app-alpha-2.log"
|
38
|
+
|
39
|
+
process.monitor_children do |children|
|
40
|
+
children.stop_command "kill {{PID}}"
|
41
|
+
end
|
42
|
+
|
43
|
+
process.group = "app-alpha"
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Bluepill.application("app", :foreground => false, :log_file => "/var/log/bluepill.log") do |app|
|
2
|
+
|
3
|
+
app.uid = "app"
|
4
|
+
app.gid = "app"
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
app.process("alpha-1") do |process|
|
10
|
+
process.start_command = "./alpha"
|
11
|
+
|
12
|
+
process.working_dir = "/tmp/app"
|
13
|
+
process.daemonize = true
|
14
|
+
process.environment = {"PORT"=>"5000"}
|
15
|
+
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
|
16
|
+
process.stop_grace_time = 45.seconds
|
17
|
+
|
18
|
+
process.stdout = process.stderr = "/var/log/app/app-alpha-1.log"
|
19
|
+
|
20
|
+
process.monitor_children do |children|
|
21
|
+
children.stop_command "kill {{PID}}"
|
22
|
+
end
|
23
|
+
|
24
|
+
process.group = "app-alpha"
|
25
|
+
end
|
26
|
+
|
27
|
+
app.process("bravo-1") do |process|
|
28
|
+
process.start_command = "./bravo"
|
29
|
+
|
30
|
+
process.working_dir = "/tmp/app"
|
31
|
+
process.daemonize = true
|
32
|
+
process.environment = {"PORT"=>"5100"}
|
33
|
+
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
|
34
|
+
process.stop_grace_time = 45.seconds
|
35
|
+
|
36
|
+
process.stdout = process.stderr = "/var/log/app/app-bravo-1.log"
|
37
|
+
|
38
|
+
process.monitor_children do |children|
|
39
|
+
children.stop_command "kill {{PID}}"
|
40
|
+
end
|
41
|
+
|
42
|
+
process.group = "app-bravo"
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>Label</key>
|
6
|
+
<string>app-alpha-1</string>
|
7
|
+
<key>ProgramArguments</key>
|
8
|
+
<array>
|
9
|
+
<string>./alpha</string>
|
10
|
+
</array>
|
11
|
+
<key>KeepAlive</key>
|
12
|
+
<true/>
|
13
|
+
<key>RunAtLoad</key>
|
14
|
+
<true/>
|
15
|
+
<key>StandardErrorPath</key>
|
16
|
+
<string>/var/log/app/app-alpha-1.log</string>
|
17
|
+
<key>UserName</key>
|
18
|
+
<string>app</string>
|
19
|
+
<key>WorkingDirectory</key>
|
20
|
+
<string>/tmp/app</string>
|
21
|
+
</dict>
|
22
|
+
</plist>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>Label</key>
|
6
|
+
<string>app-bravo-1</string>
|
7
|
+
<key>ProgramArguments</key>
|
8
|
+
<array>
|
9
|
+
<string>./bravo</string>
|
10
|
+
</array>
|
11
|
+
<key>KeepAlive</key>
|
12
|
+
<true/>
|
13
|
+
<key>RunAtLoad</key>
|
14
|
+
<true/>
|
15
|
+
<key>StandardErrorPath</key>
|
16
|
+
<string>/var/log/app/app-bravo-1.log</string>
|
17
|
+
<key>UserName</key>
|
18
|
+
<string>app</string>
|
19
|
+
<key>WorkingDirectory</key>
|
20
|
+
<string>/tmp/app</string>
|
21
|
+
</dict>
|
22
|
+
</plist>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
[program:app-alpha-1]
|
3
|
+
command=./alpha
|
4
|
+
autostart=true
|
5
|
+
autorestart=true
|
6
|
+
stopsignal=QUIT
|
7
|
+
stdout_logfile=/var/log/app/alpha-1.log
|
8
|
+
stderr_logfile=/var/log/app/alpha-1.error.log
|
9
|
+
user=app
|
10
|
+
directory=/tmp/app
|
11
|
+
environment=PORT="5000"
|
12
|
+
[program:app-bravo-1]
|
13
|
+
command=./bravo
|
14
|
+
autostart=true
|
15
|
+
autorestart=true
|
16
|
+
stopsignal=QUIT
|
17
|
+
stdout_logfile=/var/log/app/bravo-1.log
|
18
|
+
stderr_logfile=/var/log/app/bravo-1.error.log
|
19
|
+
user=app
|
20
|
+
directory=/tmp/app
|
21
|
+
environment=PORT="5100"
|
22
|
+
|
23
|
+
[group:app]
|
24
|
+
programs=app-alpha-1,app-bravo-1
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
[program:app-alpha-1]
|
3
|
+
command=./alpha
|
4
|
+
autostart=true
|
5
|
+
autorestart=true
|
6
|
+
stopsignal=QUIT
|
7
|
+
stdout_logfile=/var/log/app/alpha-1.log
|
8
|
+
stderr_logfile=/var/log/app/alpha-1.error.log
|
9
|
+
user=app
|
10
|
+
directory=/tmp/app
|
11
|
+
environment=PORT="5000"
|
12
|
+
[program:app-alpha-2]
|
13
|
+
command=./alpha
|
14
|
+
autostart=true
|
15
|
+
autorestart=true
|
16
|
+
stopsignal=QUIT
|
17
|
+
stdout_logfile=/var/log/app/alpha-2.log
|
18
|
+
stderr_logfile=/var/log/app/alpha-2.error.log
|
19
|
+
user=app
|
20
|
+
directory=/tmp/app
|
21
|
+
environment=PORT="5001"
|
22
|
+
|
23
|
+
[group:app]
|
24
|
+
programs=app-alpha-1,app-alpha-2
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
require "simplecov"
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter "/spec/"
|
6
|
+
end
|
7
|
+
|
8
|
+
require "rspec"
|
9
|
+
require "timecop"
|
10
|
+
require "fakefs/safe"
|
11
|
+
require "fakefs/spec_helpers"
|
12
|
+
|
13
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
14
|
+
|
15
|
+
def mock_export_error(message)
|
16
|
+
lambda { yield }.should raise_error(Foreman::Export::Exception, message)
|
17
|
+
end
|
18
|
+
|
19
|
+
def mock_error(subject, message)
|
20
|
+
mock_exit do
|
21
|
+
mock(subject).puts("ERROR: #{message}")
|
22
|
+
yield
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def foreman(args)
|
27
|
+
capture_stdout do
|
28
|
+
begin
|
29
|
+
Foreman::CLI.start(args.split(" "))
|
30
|
+
rescue SystemExit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def forked_foreman(args)
|
36
|
+
rd, wr = IO.pipe("BINARY")
|
37
|
+
Process.spawn("bundle exec bin/foreman #{args}", :out => wr, :err => wr)
|
38
|
+
wr.close
|
39
|
+
rd.read
|
40
|
+
end
|
41
|
+
|
42
|
+
def fork_and_capture(&blk)
|
43
|
+
rd, wr = IO.pipe("BINARY")
|
44
|
+
pid = fork do
|
45
|
+
rd.close
|
46
|
+
wr.sync = true
|
47
|
+
$stdout.reopen wr
|
48
|
+
$stderr.reopen wr
|
49
|
+
blk.call
|
50
|
+
$stdout.flush
|
51
|
+
$stdout.close
|
52
|
+
end
|
53
|
+
wr.close
|
54
|
+
Process.wait pid
|
55
|
+
buffer = ""
|
56
|
+
until rd.eof?
|
57
|
+
buffer += rd.gets
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def mock_exit(&block)
|
62
|
+
block.should raise_error(SystemExit)
|
63
|
+
end
|
64
|
+
|
65
|
+
def write_foreman_config(app)
|
66
|
+
File.open("/etc/foreman/#{app}.conf", "w") do |file|
|
67
|
+
file.puts %{#{app}_processes="alpha bravo"}
|
68
|
+
file.puts %{#{app}_alpha="1"}
|
69
|
+
file.puts %{#{app}_bravo="2"}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def write_procfile(procfile="Procfile", alpha_env="")
|
74
|
+
File.open(procfile, "w") do |file|
|
75
|
+
file.puts "alpha: ./alpha" + " #{alpha_env}".rstrip
|
76
|
+
file.puts "\n"
|
77
|
+
file.puts "bravo:\t./bravo"
|
78
|
+
end
|
79
|
+
File.expand_path(procfile)
|
80
|
+
end
|
81
|
+
|
82
|
+
def write_env(env=".env", options={"FOO"=>"bar"})
|
83
|
+
File.open(env, "w") do |file|
|
84
|
+
options.each do |key, val|
|
85
|
+
file.puts "#{key}=#{val}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def without_fakefs
|
91
|
+
FakeFS.deactivate!
|
92
|
+
ret = yield
|
93
|
+
FakeFS.activate!
|
94
|
+
ret
|
95
|
+
end
|
96
|
+
|
97
|
+
def load_export_templates_into_fakefs(type)
|
98
|
+
without_fakefs do
|
99
|
+
Dir[File.expand_path("../../data/export/#{type}/**/*", __FILE__)].inject({}) do |hash, file|
|
100
|
+
next(hash) if File.directory?(file)
|
101
|
+
hash.update(file => File.read(file))
|
102
|
+
end
|
103
|
+
end.each do |filename, contents|
|
104
|
+
FileUtils.mkdir_p File.dirname(filename)
|
105
|
+
File.open(filename, "w") do |f|
|
106
|
+
f.puts contents
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def resource_path(filename)
|
112
|
+
File.expand_path("../resources/#{filename}", __FILE__)
|
113
|
+
end
|
114
|
+
|
115
|
+
def example_export_file(filename)
|
116
|
+
FakeFS.deactivate!
|
117
|
+
data = File.read(File.expand_path(resource_path("export/#{filename}"), __FILE__))
|
118
|
+
FakeFS.activate!
|
119
|
+
data
|
120
|
+
end
|
121
|
+
|
122
|
+
def preserving_env
|
123
|
+
old_env = ENV.to_hash
|
124
|
+
begin
|
125
|
+
yield
|
126
|
+
ensure
|
127
|
+
ENV.clear
|
128
|
+
ENV.update(old_env)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def normalize_space(s)
|
133
|
+
s.gsub(/\n[\n\s]*/, "\n")
|
134
|
+
end
|
135
|
+
|
136
|
+
def capture_stdout
|
137
|
+
old_stdout = $stdout.dup
|
138
|
+
rd, wr = IO.method(:pipe).arity.zero? ? IO.pipe : IO.pipe("BINARY")
|
139
|
+
$stdout = wr
|
140
|
+
yield
|
141
|
+
wr.close
|
142
|
+
rd.read
|
143
|
+
ensure
|
144
|
+
$stdout = old_stdout
|
145
|
+
end
|
146
|
+
|
147
|
+
RSpec.configure do |config|
|
148
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
149
|
+
config.color_enabled = true
|
150
|
+
config.order = 'rand'
|
151
|
+
config.include FakeFS::SpecHelpers, :fakefs
|
152
|
+
config.mock_with :rr
|
153
|
+
end
|