foreman 0.0.2 → 0.1.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
@@ -55,6 +55,7 @@ begin
55
55
 
56
56
  s.add_dependency 'thor', '~> 0.13.6'
57
57
  end
58
+ Jeweler::GemcutterTasks.new
58
59
  rescue LoadError
59
60
  puts "Jeweler not available. Install it with: sudo gem install jeweler"
60
61
  end
data/lib/foreman.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Foreman
2
2
 
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
 
5
5
  class AppDoesNotExist < Exception; end
6
6
 
data/lib/foreman/cli.rb CHANGED
@@ -32,8 +32,6 @@ class Foreman::CLI < Thor
32
32
  config = Foreman::Configuration.new(app)
33
33
  error "No such process: #{process}." unless config.processes[process]
34
34
  config.scale(process, amount)
35
- rescue Foreman::AppDoesNotExist
36
- error "No such app: #{app}."
37
35
  end
38
36
 
39
37
  private ######################################################################
@@ -17,9 +17,9 @@ class Foreman::Configuration
17
17
  amount = amount.to_i
18
18
 
19
19
  if (old_amount < amount)
20
- ((old_amount + 1) .. amount).each { |num| run "start #{app}-#{process} NUM=#{num}" }
20
+ ((old_amount + 1) .. amount).each { |num| system "start #{app}-#{process} NUM=#{num}" }
21
21
  elsif (amount < old_amount)
22
- ((amount + 1) .. old_amount).each { |num| run "stop #{app}-#{process} NUM=#{num}" }
22
+ ((amount + 1) .. old_amount).each { |num| system "stop #{app}-#{process} NUM=#{num}" }
23
23
  end
24
24
 
25
25
  write
@@ -27,8 +27,8 @@ class Foreman::Configuration
27
27
 
28
28
  def write
29
29
  write_file "/etc/foreman/#{app}.conf", <<-UPSTART_CONFIG
30
- #{app}_processes="#{processes.keys.join(' ')}"
31
- #{processes.keys.map { |k| "#{app}_#{k}=\"#{processes[k]}\"" }.join("\n")}
30
+ #{app}_processes="#{processes.keys.sort.join(' ')}"
31
+ #{processes.keys.sort.map { |k| "#{app}_#{k}=\"#{processes[k]}\"" }.join("\n")}
32
32
  UPSTART_CONFIG
33
33
  end
34
34
 
@@ -46,10 +46,6 @@ private ######################################################################
46
46
  rescue Errno::ENOENT
47
47
  end
48
48
 
49
- def run(command)
50
- system command
51
- end
52
-
53
49
  def write_file(filename, contents)
54
50
  File.open(filename, "w") do |file|
55
51
  file.puts contents
@@ -31,12 +31,7 @@ class Foreman::Engine
31
31
  trap("TERM") { kill_and_exit("TERM") }
32
32
  trap("INT") { kill_and_exit("INT") }
33
33
 
34
- while true
35
- pid, status = Process.wait2
36
- process = running_processes.delete(pid)
37
- info "exited with code #{status}", process
38
- fork process
39
- end
34
+ run_loop
40
35
  end
41
36
 
42
37
  private ######################################################################
@@ -76,16 +71,25 @@ private ######################################################################
76
71
  end
77
72
  end
78
73
 
74
+ def proctitle(title)
75
+ $0 = title
76
+ end
77
+
79
78
  def read_procfile(procfile)
80
79
  File.read(procfile)
81
80
  end
82
81
 
83
- def running_processes
84
- @running_processes ||= {}
82
+ def run_loop
83
+ while true
84
+ pid, status = Process.wait2
85
+ process = running_processes.delete(pid)
86
+ info "exited with code #{status}", process
87
+ fork process
88
+ end
85
89
  end
86
90
 
87
- def proctitle(title)
88
- $0 = title
91
+ def running_processes
92
+ @running_processes ||= {}
89
93
  end
90
94
 
91
95
  end
@@ -62,7 +62,7 @@ describe "Foreman::CLI" do
62
62
  describe "scale" do
63
63
  describe "without an existing configuration" do
64
64
  it "displays an error" do
65
- mock_error(subject, "No such app: testapp.") do
65
+ mock_error(subject, "No such process: alpha.") do
66
66
  subject.scale("testapp", "alpha", "2")
67
67
  end
68
68
  end
@@ -1,2 +1,49 @@
1
1
  require "spec_helper"
2
2
  require "foreman/configuration"
3
+
4
+ describe "Foreman::Configuration" do
5
+ subject { Foreman::Configuration.new("testapp") }
6
+
7
+ describe "initialize" do
8
+ describe "without an existing config" do
9
+ it "has no processes" do
10
+ subject.processes.length.should == 0
11
+ end
12
+ end
13
+
14
+ describe "with an existing config" do
15
+ it "has processes" do
16
+ write_foreman_config("testapp")
17
+ subject.processes["alpha"].should == 1
18
+ subject.processes["bravo"].should == 2
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "scale" do
24
+ before(:each) { write_foreman_config("testapp") }
25
+
26
+ it "can scale up" do
27
+ mock(subject).system("start testapp-alpha NUM=2")
28
+ mock(subject).system("start testapp-alpha NUM=3")
29
+ subject.scale("alpha", 3)
30
+ end
31
+
32
+ it "can scale down" do
33
+ mock(subject).system("stop testapp-bravo NUM=2")
34
+ subject.scale("bravo", 1)
35
+ end
36
+ end
37
+
38
+ describe "wite" do
39
+ it "can write a configuration file" do
40
+ subject.scale("charlie", 3)
41
+ subject.scale("delta", 4)
42
+ File.read("/etc/foreman/testapp.conf").should == <<-FOREMAN_CONFIG
43
+ testapp_processes="charlie delta"
44
+ testapp_charlie="3"
45
+ testapp_delta="4"
46
+ FOREMAN_CONFIG
47
+ end
48
+ end
49
+ end
@@ -1,2 +1,32 @@
1
1
  require "spec_helper"
2
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
+ it "reads the processes" do
16
+ write_procfile
17
+ subject.processes["alpha"].command.should == "./alpha"
18
+ subject.processes["bravo"].command.should == "./bravo"
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "start" do
24
+ it "forks the processes" do
25
+ write_procfile
26
+ mock(subject).fork(subject.processes["alpha"])
27
+ mock(subject).fork(subject.processes["bravo"])
28
+ mock(subject).run_loop
29
+ subject.start
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.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-20 00:00:00 -04:00
18
+ date: 2010-05-21 00:00:00 -04:00
19
19
  default_executable: foreman
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency