[Groonga-commit] droonga/droonga-http-server at 1823dbd [master] Split commands to check service status and stop

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Sep 18 16:33:52 JST 2014


YUKI Hiroshi	2014-09-18 16:33:52 +0900 (Thu, 18 Sep 2014)

  New Revision: 1823dbdb0b590dc324bbf3e5b6b0c8ae5284d5ea
  https://github.com/droonga/droonga-http-server/commit/1823dbdb0b590dc324bbf3e5b6b0c8ae5284d5ea

  Message:
    Split commands to check service status and stop

  Copied files:
    bin/droonga-http-server-status
      (from bin/droonga-http-server-stop)
  Modified files:
    bin/droonga-http-server-stop

  Copied: bin/droonga-http-server-status (+1 -2) 94%
===================================================================
--- bin/droonga-http-server-stop    2014-09-18 16:18:32 +0900 (78c026a)
+++ bin/droonga-http-server-status    2014-09-18 16:33:52 +0900 (bdbfd77)
@@ -42,8 +42,7 @@ try {
             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');
+            console.log('droonga-http-server is running.');
             return true;
           })) {
         throw new Error('Couldn\'t detect droonga-engine process with the PID <' + pid + '>.');

  Modified: bin/droonga-http-server-stop (+10 -47)
===================================================================
--- bin/droonga-http-server-stop    2014-09-18 16:18:32 +0900 (78c026a)
+++ bin/droonga-http-server-stop    2014-09-18 16:33:52 +0900 (ba7ca17)
@@ -3,55 +3,18 @@
 
 var fs   = require('fs'),
     path = require('path'),
-    ps   = require('ps-node');
+    exec = require('child_process').exec;
 
-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.');
+exec('droonga-http-server-status', function(error, stdout, stderr) {
+  if (error) {
+    process.exit(false);
+    return;
+  }
 
+  var defaultConfigs = require('../lib/default-configs');
   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);
-}
+  console.log('Sending SIGTERM to the process...');
+  process.kill(pid, 'SIGTERM');
+});
-------------- next part --------------
HTML����������������������������...
Descargar 



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