[Groonga-commit] droonga/droonga-http-server at 5613018 [master] Add `droonga-http-server-stop` to kill the process

アーカイブの一覧に戻る

YUKI Hiroshi null+****@clear*****
Fri Aug 29 18:46:50 JST 2014


YUKI Hiroshi	2014-08-29 18:46:50 +0900 (Fri, 29 Aug 2014)

  New Revision: 56130189f5098bf3e6c0c27a47edddde86a7ba39
  https://github.com/droonga/droonga-http-server/commit/56130189f5098bf3e6c0c27a47edddde86a7ba39

  Message:
    Add `droonga-http-server-stop` to kill the process

  Added files:
    bin/droonga-http-server-stop
  Modified files:
    package.json

  Added: bin/droonga-http-server-stop (+57 -0) 100755
===================================================================
--- /dev/null
+++ bin/droonga-http-server-stop    2014-08-29 18:46:50 +0900 (78c026a)
@@ -0,0 +1,57 @@
+#!/usr/bin/env node
+// -*- js -*-
+
+var fs   = require('fs'),
+    path = require('path'),
+    ps   = require('ps-node');
+
+function handleError(error) {
+  console.log('Failed to detect running droonga-http-server process.');
+  console.log(error.message);
+  process.exit(false);
+}
+
+var defaultConfigs = require('../lib/default-configs');
+try {
+  if (!defaultConfigs.pid_file)
+    throw new Error('Cannot detect the location of the PID file.');
+
+  var pidFile = path.resolve(defaultConfigs.baseDir, defaultConfigs.pid_file);
+  if (!fs.existsSync(pidFile))
+    throw new Error('There is no PID file at <' + pidFile + '>');
+
+  var pid = fs.readFileSync(pidFile, 'utf8');
+  pid = pid.trim();
+  if (!/^[1-9][0-9]*$/.test(pid))
+    throw new Error('Invalid PID <' + pid + '>');
+
+  ps.lookup({ pid: pid, psargs: 'aux' }, function(error, processes) {
+    if (error)
+      handleError(error);
+
+    try {
+      if (processes.length == 0)
+        throw new Error('No such process with the PID <' + pid + '>.');
+
+      if (!processes.some(function(foundProcess) {
+            if (foundProcess.pid != pid)
+              return false;
+
+            var commandLine = foundProcess.command.indexOf('droonga-http-server') +
+                                ' ' + foundProcess.arguments.join(' ');
+            if (commandLine.indexOf('droonga-http-server') < 0)
+              throw new Error('Not a droonga-engine process: PID <' + pid + '>  (' + commandLine + ')');
+
+            console.log('Sending SIGTERM to the process...');
+            process.kill(pid, 'SIGTERM');
+            return true;
+          })) {
+        throw new Error('Couldn\'t detect droonga-engine process with the PID <' + pid + '>.');
+      }
+    } catch(error) {
+      handleError(error);
+    }
+  });
+} catch(error) {
+  handleError(error);
+}

  Modified: package.json (+1 -0)
===================================================================
--- package.json    2014-08-29 18:46:23 +0900 (09098aa)
+++ package.json    2014-08-29 18:46:50 +0900 (cd2f3dc)
@@ -27,6 +27,7 @@
     "express-session": "*",
     "js-yaml": "*",
     "morgan": "*",
+    "ps-node": "*",
     "response-time": "*",
     "winston": "*"
   },
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る