Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change the way log files are specified.

Cleanup tests a little.
  • Loading branch information...
commit ab99e652143d21a2e1be2411e476b996b8d914d0 1 parent 7b8fd31
@rkistner rkistner authored
View
1  Gemfile
@@ -5,4 +5,5 @@ gemspec
group :test do
gem 'rspec'
+ gem 'capistrano'
end
View
8 lib/foreman_god.rb
@@ -2,14 +2,6 @@
require "foreman_god/god_config"
module ForemanGod
- def self.log_path= path
- @log_path = path
- end
-
- def self.log_path
- @log_path
- end
-
# ForemanGod.watch File.dirname(__FILE__) => calls God.watch with the Procfile in the current file's folder
def self.watch dir
config = GodConfig.new(dir)
View
11 lib/foreman_god/god_config.rb
@@ -73,6 +73,10 @@ def user_name
@options[:user]
end
+ def log_path
+ @options[:log] || 'log'
+ end
+
def watch_process(name, process, n)
port = @engine.port_for(process, n)
base_env = process.instance_variable_get(:@options)[:env]
@@ -85,8 +89,11 @@ def watch_process(name, process, n)
w.interval = 60.seconds
w.env = env
w.start = process.expanded_command(env)
- if ForemanGod.log_path
- w.log = File.join(ForemanGod.log_path, "#{app_name}-#{name}-#{n}.log")
+ log = File.expand_path(log_path, process.cwd)
+ if File.directory? log
+ w.log = File.join(log, "#{app_name}-#{name}-#{n}.log")
+ else
+ LOG.warn "Log path does not exist: #{log}"
end
w.uid = user_name if user_name
View
1  samples/configuration/.foreman
@@ -1,3 +1,4 @@
formation: loop=1,another=2
app: configured-app
user: test
+log: .
View
18 spec/god_config_spec.rb
@@ -32,23 +32,27 @@
end
it "should log if log is specified" do
- ForemanGod.log_path = 'spec/tmp'
- config.watch
- watch = God.watches.values.first
- watch.log.should == 'spec/tmp/simple-loop-1.log'
+ begin
+ FileUtils.mkdir 'samples/simple/log'
+ config.watch
+ watch = God.watches.values.first
+ watch.log.should == File.absolute_path('samples/simple/log/simple-loop-1.log')
+ ensure
+ FileUtils.rm_rf 'samples/simple/log'
+ end
end
-
end
context "configuration" do
let(:config) { GodConfig.new(sample('configuration')) }
let(:user) { Etc.getlogin }
+
it "should load basic properties" do
config.dir_name.should == 'configuration'
config.app_name.should == 'configured-app'
config.user_name.should == 'test'
- config.options.should == {"formation"=>"loop=1,another=2", "app"=>"configured-app", "user"=>"test"}
+ config.options.should == {"formation"=>"loop=1,another=2", "app"=>"configured-app", "user"=>"test", "log" => "."}
end
it "should watch" do
@@ -65,7 +69,7 @@
watch.interval.should == 60.seconds
watch.env.should == {'PORT' => '5000', 'MY_VAR' => '12345', 'ANOTHER_VAR' => 'yes'}
watch.start.should == 'ruby ../simple_loop.rb -p 5000'
- watch.log.should == '/dev/null'
+ watch.log.should == File.absolute_path('samples/configuration/configured-app-loop-1.log')
watch.uid.should == user
end
View
19 spec/integration_spec.rb
@@ -1,35 +1,34 @@
# Run god and test it
require 'spec_helper'
-OPTIONS = "-p 13985 -P spec/tmp/god.pid -l spec/tmp/god.log --no-syslog"
+OPTIONS = "-p 13985 -P spec/tmp/god.pid -l #{LOG_FILE} --no-syslog"
describe "god" do
-
after do
`god #{OPTIONS} terminate`
- FileUtils.rm_rf 'samples/simple/tmp'
+ FileUtils.rm_rf 'spec/simple/tmp'
end
it "should run and terminate a script" do
- `god #{OPTIONS} --attach #{Process.pid} -c spec/simple.god`
+ `god #{OPTIONS} --attach #{Process.pid} -c spec/simple/simple.god`
sleep 1
`god #{OPTIONS} terminate`
- #puts File.read('spec/tmp/god.log')
+
File.read('spec/tmp/simple-loop-1.log').should == "Starting simple loop\nTerminated loop with #<SignalException: SIGTERM>\n"
end
it "should restart a script on file touch" do
- `god #{OPTIONS} --attach #{Process.pid} -c spec/simple.god`
+ `god #{OPTIONS} --attach #{Process.pid} -c spec/simple/simple.god`
sleep 1
- FileUtils.mkdir_p 'samples/simple/tmp'
- FileUtils.touch 'samples/simple/tmp/restart.txt'
+ FileUtils.mkdir_p 'spec/simple/tmp'
+ FileUtils.touch 'spec/simple/tmp/restart.txt'
- sleep 5
+ sleep 6 # Currently the file is checked every 5 seconds
`god #{OPTIONS} terminate`
- #puts File.read('spec/tmp/god.log')
+
File.read('spec/tmp/simple-loop-1.log').should == "Starting simple loop\nTerminated loop with #<SignalException: SIGTERM>\n"*2
end
end
View
6 spec/simple.god
@@ -1,6 +0,0 @@
-require 'foreman_god'
-
-ForemanGod.log_path = File.join(File.dirname(__FILE__), 'tmp')
-puts ForemanGod.log_path.inspect
-puts File.join(File.dirname(__FILE__), '..', 'samples', 'simple').inspect
-ForemanGod.watch File.join(File.dirname(__FILE__), '..', 'samples', 'simple')
View
1  spec/simple/.foreman
@@ -0,0 +1 @@
+log: ../tmp
View
1  spec/simple/Procfile
@@ -0,0 +1 @@
+loop: ruby simple_loop.rb -p $PORT
View
3  spec/simple/simple.god
@@ -0,0 +1,3 @@
+require 'foreman_god'
+
+ForemanGod.watch File.dirname(__FILE__)
View
8 spec/simple/simple_loop.rb
@@ -0,0 +1,8 @@
+puts "Starting simple loop"
+begin
+ while true
+ sleep 1
+ end
+rescue Exception => e
+ puts "Terminated loop with #{e.inspect}"
+end
View
9 spec/spec_helper.rb
@@ -3,6 +3,12 @@
require 'god'
require 'foreman_god'
+LOG_FILE = 'god.log'
+FileUtils.rm_r LOG_FILE
+
+Object.send(:remove_const, :LOG)
+LOG = God::Logger.new(File.open(LOG_FILE, 'w'))
+
include ForemanGod
def sample(name)
@@ -31,12 +37,11 @@ def self.reset
# Clean/Reset God's state prior to running the tests
config.before :each do
God.reset
- ForemanGod.log_path = nil
FileUtils.rm_rf 'spec/tmp'
FileUtils.mkdir_p 'spec/tmp'
end
config.after :each do
- #FileUtils.rm_rf 'spec/tmp'
+ FileUtils.rm_rf 'spec/tmp'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.