[Groonga-commit] droonga/droonga-engine at a134b44 [master] Write serf port number file by custom event "change_port"

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Jun 26 17:30:16 JST 2014


YUKI Hiroshi	2014-06-26 17:30:16 +0900 (Thu, 26 Jun 2014)

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

  Message:
    Write serf port number file by custom event "change_port"

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

  Modified: lib/droonga/command/serf_event_handler.rb (+22 -1)
===================================================================
--- lib/droonga/command/serf_event_handler.rb    2014-06-26 17:29:52 +0900 (eda34e6)
+++ lib/droonga/command/serf_event_handler.rb    2014-06-26 17:30:16 +0900 (f563a89)
@@ -33,11 +33,13 @@ module Droonga
 
       def initialize
         @serf = ENV["SERF"] || Serf.path
-        @serf_rpc_address = ENV["SERF_RPC_ADDRESS"] || "127.0.0.1:7373"
+        @serf_port = ENV["SERF_PORT"] || Serf.default_port
+        @serf_rpc_address = ENV["SERF_RPC_ADDRESS"] || "127.0.0.1:#{@serf_port}"
       end
 
       def run
         parse_event
+        process_event
 
         output_live_nodes
         true
@@ -46,11 +48,22 @@ module Droonga
       private
       def parse_event
         @event_name = ENV["SERF_EVENT"]
+        @payload = nil
         case @event_name
         when "user"
           @event_name += ":#{ENV["SERF_USER_EVENT"]}"
+          @payload = $stdin.gets
         when "query"
           @event_name += ":#{ENV["SERF_USER_QUERY"]}"
+          @payload = $stdin.gets
+        end
+      end
+
+      def process_event
+        if @event_name == "user:change_port" or
+           @event_name == "query:change_port"
+          serf_port =****@paylo*****_i
+          output_port_file(serf_port)
         end
       end
 
@@ -72,6 +85,14 @@ module Droonga
         path = Path.live_nodes
         nodes = live_nodes
         file_contents = JSON.pretty_generate(nodes)
+        output(path, file_contents)
+      end
+
+      def output_port_file(port)
+        output(Serf.port_file, port)
+      end
+
+      def output(path, file_contents)
         FileUtils.mkdir_p(path.parent.to_s)
         # Don't output the file directly to prevent loading of incomplete file!
         Tempfile.open(path.basename.to_s, path.parent.to_s, "w") do |output|
-------------- next part --------------
HTML����������������������������...
Download 



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