Permalink
Browse files

Log script which may or may not work

  • Loading branch information...
Michael Sofaer and Raphael Sofaer
Michael Sofaer and Raphael Sofaer committed Nov 20, 2010
1 parent df36889 commit 2a5a6265ac38281c7e3e456e765ec6d5e3014f2b
Showing with 39 additions and 8 deletions.
  1. +19 −6 lib/hellspawn.rb
  2. +19 −2 test/hellspawn_test.rb
  3. +1 −0 test/test_helper.rb
View
@@ -6,9 +6,13 @@ class Legion < Array
def initialize(options)
@options = options
end
+ def log_dir
+ @options[:log_dir]
+ end
def march!
FileUtils.rm_rf(@options[:base])
- each {|daemon| daemon.march!(@options[:base])}
+ FileUtils.mkdir_p(log_dir) if log_dir
+ each {|daemon| daemon.march!(@options[:base], log_dir)}
end
def summon(options)
@@ -33,19 +37,28 @@ def initialize(options)
def name
self[:name]
end
- def march!(base)
+ def march!(base, log_dir = nil)
FileUtils.mkdir_p File.join(base, name)
- run_file = File.open(File.join(base, name, "run"), "w+")
- run_file.puts run_prep
- run_file.puts run_script
- run_file.close
+ File.open(File.join(base, name, "run"), "w+") do |f|
+ f.puts run_prep
+ f.puts run_script
+ end
+ if log_dir
+ FileUtils.mkdir_p File.join(base, name, 'log')
+ File.open(File.join(base, name,'log', "run"), "w+") do |f|
+ f.puts log_script(log_dir)
+ end
+ end
end
def run_script
"exec #{self[:executable]} " + flag_snippet
end
def flag_snippet
self[:flags].map{|k,v| k + " " + v.to_s}.join(" ")
end
+ def log_script log_dir
+ "exec multilog #{log_dir}/#{self[:name]}.log"
+ end
def run_prep
"exec 2&>1"
end
View
@@ -10,7 +10,8 @@ def setup
},
}
@base = "/tmp/test_services"
- @legion = Hellspawn.legion(:base => @base, :name => "test_legion")
+ @legion = Hellspawn.legion(:base => @base,
+ :log_dir => "/tmp/test_services_log")
end
def teardown
FileUtils.rm_rf @base
@@ -28,6 +29,22 @@ def test_march
run_script = File.read("#{@base}/thin/run")
assert { run_script.match /exec \/usr\/local\/bin\/thin/ }
end
+ def test_legion_log_dir
+ @legion.summon @thin
+ @legion.march!
+ assert { Dir.glob(@legion.log_dir) == [ @legion.log_dir]}
+ end
+ def test_daemon_log_dir
+ @legion.summon @thin
+ @legion.march!
+ assert { Dir.glob("#{@base}/thin/log/run") == ["#{@base}/thin/log/run"]}
+ end
+ def test_daemon_log_script
+ @legion.summon @thin
+ @legion.march!
+ run_script = File.read("#{@base}/thin/log/run")
+ assert { run_script.split("\n").first == "exec multilog #{@legion.log_dir}/thin.log" }
+ end
def test_flags
@legion.summon @thin
@legion.march!
@@ -43,7 +60,7 @@ def test_stderr
def test_removal
@legion.summon @thin
@legion.march!
- Hellspawn.legion(:base => @base, :name => "empty_legion").march!
+ Hellspawn.legion(:base => @base).march!
assert {Dir.glob("#{@base}/*") == [] }
end
def test_squad_by_flag
View
@@ -1,5 +1,6 @@
require 'rubygems'
require 'test/unit'
+require 'pp'
require 'wrong'
require 'wrong/adapters/test_unit'
Wrong.config[:color] = true

0 comments on commit 2a5a626

Please sign in to comment.