[Groonga-commit] long-long-float/droonga-engine at 6f98650 [master] Add a utility command `droonga-engine-stop` to kill the server

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Aug 29 17:57:54 JST 2014


YUKI Hiroshi	2014-08-29 17:57:54 +0900 (Fri, 29 Aug 2014)

  New Revision: 6f9865091afce69433c97595c5a4982ac3480b95
  https://github.com/long-long-float/droonga-engine/commit/6f9865091afce69433c97595c5a4982ac3480b95

  Message:
    Add a utility command `droonga-engine-stop` to kill the server

  Added files:
    bin/droonga-engine-stop
  Modified files:
    droonga-engine.gemspec

  Added: bin/droonga-engine-stop (+64 -0) 100755
===================================================================
--- /dev/null
+++ bin/droonga-engine-stop    2014-08-29 17:57:54 +0900 (774bd4a)
@@ -0,0 +1,64 @@
+#!/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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "optparse"
+require "sys/proctable"
+
+require "droonga/command/droonga_engine"
+
+configuration = Droonga::Command::DroongaEngine::Configuration.new
+parser = OptionParser.new
+configuration.add_command_line_options(parser)
+parser.parse!(ARGV)
+
+class Failed < StandardError
+  attr_reader :message
+
+  def initialize(message)
+    @message = message
+  end
+end
+
+begin
+  pid_file = configuration.pid_file_path
+  unless pid_file.exist?
+    raise Failed.new("There is no PID file at <#{pid_file.to_s}>.")
+  end
+
+  pid = File.read(pid_file).strip
+  unless pid =~ /\A[1-9][0-9]*\z/
+    raise Failed.new("Invalid PID <#{pid}>.")
+  end
+
+  pid = pid.to_i
+  process_info = Sys::ProcTable.ps(pid)
+  unless process_info
+    raise Failed.new("No such process with the PID <#{pid}>.")
+  end
+  unless process_info.cmdline.include?("droonga-engine")
+    raise Failed.new("Not a droonga-engine process: PID <#{pid}> (#{process_info.cmdline})")
+  end
+
+  Process.kill(:TERM, pid)
+
+rescue Failed => error
+  puts "Failed to detect running droonga-engine process."
+  puts error.message
+  exit(false)
+end
+
+exit(true)

  Modified: droonga-engine.gemspec (+1 -0)
===================================================================
--- droonga-engine.gemspec    2014-08-29 17:43:58 +0900 (a5af5db)
+++ droonga-engine.gemspec    2014-08-29 17:57:54 +0900 (4a4b342)
@@ -47,6 +47,7 @@ Gem::Specification.new do |gem|
   gem.add_dependency "rroonga", ">= 4.0.1"
   gem.add_dependency "sigdump"
   gem.add_dependency "slop"
+  gem.add_dependency "sys-proctable"
   gem.add_development_dependency "kramdown"
   gem.add_development_dependency "bundler"
   gem.add_development_dependency "packnga"
-------------- next part --------------
HTML����������������������������...
Download 



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