Permalink
Browse files

Thor task for logrotate

  • Loading branch information...
1 parent 98aa0a7 commit 3f664ece10d3fcc95229e0164337b69e2385bb89 Gleb Pomykalov committed Nov 9, 2011
Showing with 43 additions and 0 deletions.
  1. +13 −0 lib/daemonizer/cli.rb
  2. +15 −0 spec/cli/not_started_spec.rb
  3. +15 −0 spec/cli/started_spec.rb
View
@@ -109,6 +109,19 @@ def stats(pool_name = nil)
end
end
+ desc "logrotate", "Reopen all log files"
+ def logrotate(pool_name = nil)
+ control_pools_loop(pool_name, "log file reopened") do |pool|
+ # Pid file check
+ unless Daemonize.check_pid(pool.pid_file)
+ print_pool pool.name, "not started!"
+ exit(1)
+ end
+
+ Process.kill('HUP', Daemonize.read_pid(pool.pid_file))
+ end
+ end
+
private
def control_pools_loop(pool_name, message = nil, debug = false, &block)
if debug
@@ -21,6 +21,21 @@
end
end
+ describe "on call 'logrotate'" do
+ before(:each) do
+ daemonizer :logrotate
+ end
+
+ it "should return valid text" do
+ @out.should match(/test1: not started/)
+ @out.should match(/test2: not started/)
+ end
+
+ it "should not return anything to stderr" do
+ @err.should == ''
+ end
+ end
+
describe "on call 'start'" do
describe "with all pools" do
before(:each) do
View
@@ -26,6 +26,21 @@
end
end
+ describe "on call 'logrotate'" do
+ before(:each) do
+ daemonizer :logrotate
+ end
+
+ it "should return valid text" do
+ @out.should match(/test1: log file reopened/)
+ @out.should match(/test2: log file reopened/)
+ end
+
+ it "should not return anything to stderr" do
+ @err.should == ''
+ end
+ end
+
describe "on call 'start'" do
describe "with all pools" do
before(:each) do

0 comments on commit 3f664ec

Please sign in to comment.