From 675ad2630d28d16fbb207c3adde82f8b39042db8 Mon Sep 17 00:00:00 2001 From: David Dollar Date: Wed, 9 Jun 2010 11:51:10 -0400 Subject: [PATCH] cleanup --- Rakefile | 2 +- lib/foreman/engine.rb | 24 +++++++++++++++++------- spec/foreman/cli_spec.rb | 6 ++---- spec/spec_helper.rb | 4 +++- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Rakefile b/Rakefile index 189b5ed..dca4848 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ -require "rubygems" require "rake" +require "rspec" require "rspec/core/rake_task" $:.unshift File.expand_path("../lib", __FILE__) diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index d55ff93..a6c0d1f 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -34,23 +34,33 @@ class Foreman::Engine run_loop end + def execute(name) + run(processes[name], false) + end + private ###################################################################### def fork(process) pid = Process.fork do - proctitle "ruby: foreman #{process.name}" - - Dir.chdir directory do - FileUtils.mkdir_p "log" - system "#{process.command} >>log/#{process.name}.log 2>&1" - exit $?.exitstatus || 255 - end + run(process) end info "started with pid #{pid}", process running_processes[pid] = process end + def run(process, log_to_file=true) + proctitle "ruby: foreman #{process.name}" + + Dir.chdir directory do + FileUtils.mkdir_p "log" + command = process.command + command << " >>log/#{process.name}.log 2>&1" if log_to_file + system command + exit $?.exitstatus || 255 + end + end + def kill_and_exit(signal="TERM") info "termination requested" running_processes.each do |pid, process| diff --git a/spec/foreman/cli_spec.rb b/spec/foreman/cli_spec.rb index 8ddffeb..70317ba 100644 --- a/spec/foreman/cli_spec.rb +++ b/spec/foreman/cli_spec.rb @@ -5,9 +5,7 @@ describe "Foreman::CLI" do subject { Foreman::CLI.new } describe "start" do - #let(:engine) { stub_engine } - - describe "with a non-existent Procifile" do + describe "with a non-existent Procfile" do it "prints an error" do mock_error(subject, "Procfile does not exist.") do dont_allow.instance_of(Foreman::Engine).start @@ -28,7 +26,7 @@ describe "Foreman::CLI" do end describe "export" do - describe "with a non-existent Procifile" do + describe "with a non-existent Procfile" do it "prints an error" do mock_error(subject, "Procfile does not exist.") do dont_allow.instance_of(Foreman::Engine).export diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c4b9c8..b8fe97f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,7 @@ -require "fakefs/spec_helpers" +require "rubygems" require "rspec" +require "fakefs/safe" +require "fakefs/spec_helpers" $:.unshift "lib"