[Groonga-commit] droonga/droonga-engine at 2d2ebe6 [master] droonga-engine: support re-opening log file by SIGHUP or SIGUSR1

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jan 5 17:45:29 JST 2015


Kouhei Sutou	2015-01-05 17:45:29 +0900 (Mon, 05 Jan 2015)

  New Revision: 2d2ebe64a5cd46625a7ec6f4431ea16c97ff40c0
  https://github.com/droonga/droonga-engine/commit/2d2ebe64a5cd46625a7ec6f4431ea16c97ff40c0

  Message:
    droonga-engine: support re-opening log file by SIGHUP or SIGUSR1

  Modified files:
    lib/droonga/command/droonga_engine.rb

  Modified: lib/droonga/command/droonga_engine.rb (+34 -33)
===================================================================
--- lib/droonga/command/droonga_engine.rb    2015-01-05 17:41:12 +0900 (b27083b)
+++ lib/droonga/command/droonga_engine.rb    2015-01-05 17:45:29 +0900 (b7a0002)
@@ -55,11 +55,7 @@ module Droonga
           Process.daemon
         end
 
-        open_log_file do
-          write_pid_file do
-            run_main_loop
-          end
-        end
+        run_main_loop
       end
 
       private
@@ -91,33 +87,6 @@ module Droonga
         main_loop.run
       end
 
-      def open_log_file
-        if****@confi*****_file_path
-          @configuration.log_file_path.open("a") do |file|
-            $stdout.reopen(file)
-            $stderr.reopen(file)
-            yield
-          end
-        else
-          yield
-        end
-      end
-
-      def write_pid_file
-        if****@confi*****_file_path
-          @configuration.pid_file_path.open("w") do |file|
-            file.puts(Process.pid)
-          end
-          begin
-            yield
-          ensure
-            FileUtils.rm_f(@configuration.pid_file_path.to_s)
-          end
-        else
-          yield
-        end
-      end
-
       class Configuration
         attr_reader :ready_notify_fd
         def initialize
@@ -341,9 +310,40 @@ module Droonga
         def initialize(configuration)
           @configuration = configuration
           @loop = Coolio::Loop.default
+          @log_file = nil
         end
 
         def run
+          reopen_log_file
+          write_pid_file do
+            run_internal
+          end
+        end
+
+        private
+        def reopen_log_file
+          return if****@confi*****_file_path.nil?
+          @log_file =****@confi*****_file_path.open("a")
+          $stdout.reopen(@log_file)
+          $stderr.reopen(@log_file)
+        end
+
+        def write_pid_file
+          if****@confi*****_file_path
+            @configuration.pid_file_path.open("w") do |file|
+              file.puts(Process.pid)
+            end
+            begin
+              yield
+            ensure
+              FileUtils.rm_f(@configuration.pid_file_path.to_s)
+            end
+          else
+            yield
+          end
+        end
+
+        def run_internal
           start_serf
           @service_runner = run_service
           setup_initial_on_ready
@@ -356,7 +356,6 @@ module Droonga
           @service_runner.success?
         end
 
-        private
         def setup_initial_on_ready
           return if****@confi*****_notify_fd.nil?
           @service_runner.on_ready = lambda do
@@ -406,6 +405,7 @@ module Droonga
 
         def restart_graceful
           old_service_runner = @service_runner
+          reopen_log_file
           @service_runner = run_service
           @service_runner.on_ready = lambda do
             @service_runner.on_failure = nil
@@ -419,6 +419,7 @@ module Droonga
 
         def restart_immediately
           old_service_runner = @service_runner
+          reopen_log_file
           @service_runner = run_service
           old_service_runner.stop_immediately
         end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index