[Groonga-commit] droonga/droonga-engine at b99cbfc [master] Fetch catalog.json from source host directly

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Jul 1 19:07:07 JST 2014


YUKI Hiroshi	2014-07-01 19:07:07 +0900 (Tue, 01 Jul 2014)

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

  Message:
    Fetch catalog.json from source host directly

  Added files:
    bin/droonga-engine-data-publisher
  Modified files:
    droonga-engine.gemspec
    lib/droonga/command/serf_event_handler.rb
    lib/droonga/path.rb

  Added: bin/droonga-engine-data-publisher (+69 -0) 100644
===================================================================
--- /dev/null
+++ bin/droonga-engine-data-publisher    2014-07-01 19:07:07 +0900 (cc70529)
@@ -0,0 +1,69 @@
+#!/usr/bin/env ruby
+#
+# Copyright (C) 2014 Droonga Project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+require "ostruct"
+require "optparse"
+require "pathname"
+require "fileutils"
+require "webrick"
+
+require "droonga/engine/version"
+require "droonga/path"
+
+options = OpenStruct.new
+options.base_dir = ENV[Droonga::Path::BASE_DIR_ENV_NAME] || Dir.pwd
+options.port = 10032
+
+parser = OptionParser.new
+parser.version = Droonga::Engine::VERSION
+
+parser.on("--base-dir=PATH",
+          "Path to the base directory the catalog.json is located in.",
+          "(#{options.base_dir})") do |path|
+  options.base_dir = path
+end
+parser.on("--port=PORT", Integer,
+          "Port number to listen.",
+          "(#{options.port})") do |port|
+  options.port = port
+end
+parser.on("--published-file=PATH",
+          "Path to the file to be published.") do |path|
+  options.published_file = path
+end
+
+parser.parse!(ARGV)
+
+include WEBrick
+
+published_dir = Droonga::Path.published(options.port)
+FileUtils.mkdir_p(published_dir.to_s)
+published_file = Pathname(options.published_file).expand_path
+File.copy(published_file.to_s, published_dir + published_file.basename)
+File.open(published_dir + ".pid", "w") do |file|
+  file.puts(Process.pid)
+end
+
+server = HTTPServer.new(:Port => options.port,
+                        :DocumentRoot => published_dir)
+
+trap("INT") do
+  server.shutdown
+  FileUtils.rm_rf(published_dir.to_s)
+end
+
+server.start

  Modified: droonga-engine.gemspec (+1 -0)
===================================================================
--- droonga-engine.gemspec    2014-07-01 17:11:13 +0900 (11e7017)
+++ droonga-engine.gemspec    2014-07-01 19:07:07 +0900 (d2edc2a)
@@ -46,6 +46,7 @@ Gem::Specification.new do |gem|
   gem.add_dependency "archive-zip"
   gem.add_dependency "sigdump"
   gem.add_dependency "drndump"
+  gem.add_dependency "webrick"
   gem.add_development_dependency "rake"
   gem.add_development_dependency "bundler"
   gem.add_development_dependency "test-unit"

  Modified: lib/droonga/command/serf_event_handler.rb (+14 -3)
===================================================================
--- lib/droonga/command/serf_event_handler.rb    2014-07-01 17:11:13 +0900 (717790a)
+++ lib/droonga/command/serf_event_handler.rb    2014-07-01 19:07:07 +0900 (9ab7d9b)
@@ -14,6 +14,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 require "json"
+require "open3"
 
 require "droonga/path"
 require "droonga/serf"
@@ -184,7 +185,8 @@ module Droonga
         catalog = response.body
 
         Serf.send_query(source_node, "unpublish_catalog",
-                        "node" => source_node)
+                        "node" => source_node,
+                        "port" => port)
 
         JSON.parse(catalog)
       end
@@ -193,11 +195,20 @@ module Droonga
         port = @payload["port"]
         return unless port
 
-        # TODO: implement me!
+        system("droonga-engine-data-publisher",
+                 "--base-dir", Path.base.to_s,
+                 "--port", port.to_s,
+                 "--published-file", Path.catalog.to_s)
       end
 
       def unpublish_catalog
-        # TODO: implement me!
+        port = @payload["port"]
+        return unless port
+
+        published_dir = Path.published(port)
+        pid_file = published_dir + ".pid"
+
+        Process.kill("INT", pid_file.read.to_i)
       end
 
       def set_replicas

  Modified: lib/droonga/path.rb (+4 -0)
===================================================================
--- lib/droonga/path.rb    2014-07-01 17:11:13 +0900 (d18768d)
+++ lib/droonga/path.rb    2014-07-01 19:07:07 +0900 (6055c3e4)
@@ -55,6 +55,10 @@ module Droonga
         Pathname.new(base_file_name).expand_path(base)
       end
 
+      def published(suffix)
+        base + "published-#{suffix}"
+      end
+
       def buffer
         state + "buffer"
       end
-------------- next part --------------
HTML����������������������������...
下載 



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