[Groonga-commit] droonga/droonga-http-server at eabe10a [master] Save generated config file

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Sep 18 20:12:09 JST 2014


YUKI Hiroshi	2014-09-18 20:12:09 +0900 (Thu, 18 Sep 2014)

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

  Message:
    Save generated config file

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

  Modified: bin/droonga-http-server-configure (+27 -6)
===================================================================
--- bin/droonga-http-server-configure    2014-09-18 20:08:58 +0900 (f77ef68)
+++ bin/droonga-http-server-configure    2014-09-18 20:12:09 +0900 (9ce67a4)
@@ -4,12 +4,15 @@
 var promptly = require('promptly'),
     exec     = require('child_process').exec,
     fs       = require('fs'),
+    yaml     = require('js-yaml'),
     path     = require('path'),
-    touch    = require('touch');
+    touch    = require('touch'),
+    uid      = require('uid-number');
 
 var defaultConfigs = require('../lib/default-configs');
 
 var serviceUserName    = 'droonga-http-server';
+var serviceGroupName   = serviceUserName;
 var serviceBaseDir     = '/home/' + serviceUserName + '/droonga';
 
 var options            = null;
@@ -127,9 +130,12 @@ function parseOptions() {
               .parse(process.argv);
 }
 
+function configFilePath() {
+  return path.resolve(baseDir, 'droonga-http-server.yaml');
+}
+
 function configFileExists() {
-  var configFile = path.resolve(baseDir, 'droonga-http-server.yaml');
-  return fs.existsSync(configFile);
+  return fs.existsSync(configFilePath());
 }
 
 function confirmToReconfigure(callback) {
@@ -279,9 +285,24 @@ function writeNewConfigs(callback) {
   engineConfigs.receiver_host   = configValues.receiverHostName;
   configs.engine = engineConfigs;
 
-  console.log(configs); // TODO: Implement codes to write configs to the file.
-  // TODO: Change permission of the generated config file.
-  callback();
+  var configYaml = yaml.safeDump(configs);
+  safeWriteFileSync(configFilePath(), configYaml, { encoding: 'utf8' });
+
+  if (installedAsService) {
+    uid(serviceUserName, serviceGroupName, function(error, uid, gid) {
+      fs.chownSync(configFilePath(), uid, gid);
+      callback();
+    });
+  }
+  else {
+    callback();
+  }
+}
+
+function safeWriteFileSync(path, data, options) {
+  var tempFilePath = path + '.' + Date.now();
+  fs.writeFileSync(tempFilePath, data, options);
+  fs.renameSync(tempFilePath, path);
 }
 
 function finish() {

  Modified: package.json (+1 -0)
===================================================================
--- package.json    2014-09-18 20:08:58 +0900 (b410e58)
+++ package.json    2014-09-18 20:12:09 +0900 (194dbd5)
@@ -31,6 +31,7 @@
     "ps-node": "*",
     "response-time": "*",
     "touch": "*",
+    "uid-number": "*",
     "winston": "*"
   },
   "bin": {
-------------- next part --------------
HTML����������������������������...
Download 



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