foreman 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,6 +1,6 @@
1
1
  module Foreman
2
2
 
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
 
5
5
  class AppDoesNotExist < Exception; end
6
6
 
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")
@@ -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
- proctitle "ruby: foreman #{process.name}"
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|
@@ -50,7 +50,7 @@ exec #{process.command} >>/var/log/#{app}/#{process.name}.log 2>&1
50
50
  end
51
51
 
52
52
  engine.processes.each do |name, process|
53
- config.processes[name] ||= 1
53
+ config.scale(name, 1)
54
54
  end
55
55
  config.write
56
56
  end
@@ -5,9 +5,7 @@ describe "Foreman::CLI" do
5
5
  subject { Foreman::CLI.new }
6
6
 
7
7
  describe "start" do
8
- #let(:engine) { stub_engine }
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 Procifile" do
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
@@ -29,4 +29,12 @@ describe "Foreman::Engine" do
29
29
  subject.start
30
30
  end
31
31
  end
32
+
33
+ describe "execute" do
34
+ it "runs the processes" do
35
+ write_procfile
36
+ mock(subject).run(subject.processes["alpha"], false)
37
+ subject.execute("alpha")
38
+ end
39
+ end
32
40
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
- require "fakefs/spec_helpers"
1
+ require "rubygems"
2
2
  require "rspec"
3
+ require "fakefs/safe"
4
+ require "fakefs/spec_helpers"
3
5
 
4
6
  $:.unshift "lib"
5
7
 
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
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-05-21 00:00:00 -04:00
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: false
144
+ has_rdoc: true
145
145
  homepage: http://github.com/ddollar/foreman
146
146
  licenses: []
147
147