foreman 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -2
- data/lib/foreman.rb +1 -1
- data/lib/foreman/cli.rb +14 -0
- data/lib/foreman/engine.rb +31 -7
- data/lib/foreman/export/upstart.rb +1 -1
- data/spec/foreman/cli_spec.rb +23 -4
- data/spec/foreman/engine_spec.rb +8 -0
- data/spec/spec_helper.rb +3 -1
- metadata +6 -6
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "rubygems"
|
2
1
|
require "rake"
|
2
|
+
require "rspec"
|
3
3
|
require "rspec/core/rake_task"
|
4
4
|
|
5
5
|
$:.unshift File.expand_path("../lib", __FILE__)
|
@@ -55,7 +55,6 @@ begin
|
|
55
55
|
|
56
56
|
s.add_dependency 'thor', '~> 0.13.6'
|
57
57
|
end
|
58
|
-
Jeweler::GemcutterTasks.new
|
59
58
|
rescue LoadError
|
60
59
|
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
61
60
|
end
|
data/lib/foreman.rb
CHANGED
data/lib/foreman/cli.rb
CHANGED
@@ -13,6 +13,20 @@ class Foreman::CLI < Thor
|
|
13
13
|
Foreman::Engine.new(procfile).start
|
14
14
|
end
|
15
15
|
|
16
|
+
desc "execute PROCESS [PROCFILE]", "Run an instance of the specified process from PROCFILE"
|
17
|
+
|
18
|
+
def execute(process, procfile="Procfile")
|
19
|
+
error "#{procfile} does not exist." unless procfile_exists?(procfile)
|
20
|
+
Foreman::Engine.new(procfile).execute(process)
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "screen [PROCFILE]", "Run the app described in PROCFILE as screen windows"
|
24
|
+
|
25
|
+
def screen(procfile="Procfile")
|
26
|
+
error "#{procfile} does not exist." unless procfile_exists?(procfile)
|
27
|
+
Foreman::Engine.new(procfile).screen
|
28
|
+
end
|
29
|
+
|
16
30
|
desc "export APP [PROCFILE] [FORMAT]", "Export the app described in PROCFILE as APP to another FORMAT"
|
17
31
|
|
18
32
|
def export(app, procfile="Procfile", format="upstart")
|
data/lib/foreman/engine.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "foreman"
|
2
2
|
require "foreman/process"
|
3
|
+
require "tempfile"
|
3
4
|
|
4
5
|
class Foreman::Engine
|
5
6
|
|
@@ -34,23 +35,46 @@ class Foreman::Engine
|
|
34
35
|
run_loop
|
35
36
|
end
|
36
37
|
|
38
|
+
def screen
|
39
|
+
tempfile = Tempfile.new("foreman")
|
40
|
+
tempfile.puts "sessionname foreman"
|
41
|
+
processes.each do |name, process|
|
42
|
+
tempfile.puts "screen -t #{name} #{process.command}"
|
43
|
+
end
|
44
|
+
tempfile.close
|
45
|
+
|
46
|
+
system "screen -c #{tempfile.path}"
|
47
|
+
|
48
|
+
tempfile.delete
|
49
|
+
end
|
50
|
+
|
51
|
+
def execute(name)
|
52
|
+
run(processes[name], false)
|
53
|
+
end
|
54
|
+
|
37
55
|
private ######################################################################
|
38
56
|
|
39
57
|
def fork(process)
|
40
58
|
pid = Process.fork do
|
41
|
-
|
42
|
-
|
43
|
-
Dir.chdir directory do
|
44
|
-
FileUtils.mkdir_p "log"
|
45
|
-
system "#{process.command} >>log/#{process.name}.log 2>&1"
|
46
|
-
exit $?.exitstatus || 255
|
47
|
-
end
|
59
|
+
run(process)
|
48
60
|
end
|
49
61
|
|
50
62
|
info "started with pid #{pid}", process
|
51
63
|
running_processes[pid] = process
|
52
64
|
end
|
53
65
|
|
66
|
+
def run(process, log_to_file=true)
|
67
|
+
proctitle "ruby: foreman #{process.name}"
|
68
|
+
|
69
|
+
Dir.chdir directory do
|
70
|
+
FileUtils.mkdir_p "log"
|
71
|
+
command = process.command
|
72
|
+
command << " >>log/#{process.name}.log 2>&1" if log_to_file
|
73
|
+
system command
|
74
|
+
exit $?.exitstatus || 255
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
54
78
|
def kill_and_exit(signal="TERM")
|
55
79
|
info "termination requested"
|
56
80
|
running_processes.each do |pid, process|
|
data/spec/foreman/cli_spec.rb
CHANGED
@@ -5,9 +5,7 @@ describe "Foreman::CLI" do
|
|
5
5
|
subject { Foreman::CLI.new }
|
6
6
|
|
7
7
|
describe "start" do
|
8
|
-
|
9
|
-
|
10
|
-
describe "with a non-existent Procifile" do
|
8
|
+
describe "with a non-existent Procfile" do
|
11
9
|
it "prints an error" do
|
12
10
|
mock_error(subject, "Procfile does not exist.") do
|
13
11
|
dont_allow.instance_of(Foreman::Engine).start
|
@@ -27,8 +25,29 @@ describe "Foreman::CLI" do
|
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
28
|
+
describe "execute" do
|
29
|
+
describe "with a non-existent Procfile" do
|
30
|
+
it "prints an error" do
|
31
|
+
mock_error(subject, "Procfile does not exist.") do
|
32
|
+
dont_allow.instance_of(Foreman::Engine).start
|
33
|
+
subject.execute("alpha")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "with a Procfile" do
|
39
|
+
before(:each) { write_procfile }
|
40
|
+
|
41
|
+
it "runs successfully" do
|
42
|
+
dont_allow(subject).error
|
43
|
+
mock.instance_of(Foreman::Engine).execute("alpha")
|
44
|
+
subject.execute("alpha")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
30
49
|
describe "export" do
|
31
|
-
describe "with a non-existent
|
50
|
+
describe "with a non-existent Procfile" do
|
32
51
|
it "prints an error" do
|
33
52
|
mock_error(subject, "Procfile does not exist.") do
|
34
53
|
dont_allow.instance_of(Foreman::Engine).export
|
data/spec/foreman/engine_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Dollar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-06-09 00:00:00 -04:00
|
19
19
|
default_executable: foreman
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -141,7 +141,7 @@ files:
|
|
141
141
|
- spec/foreman_spec.rb
|
142
142
|
- spec/spec_helper.rb
|
143
143
|
- README.rdoc
|
144
|
-
has_rdoc:
|
144
|
+
has_rdoc: true
|
145
145
|
homepage: http://github.com/ddollar/foreman
|
146
146
|
licenses: []
|
147
147
|
|