-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvccutil.js
More file actions
47 lines (43 loc) · 1.34 KB
/
vccutil.js
File metadata and controls
47 lines (43 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var logger = require("./log.js");
var fs = require('fs');
var path = require('path');
var yaml = require('yamljs');
var promise = require("deferred");
var sd = require('systemd-daemon');
exports.systemdNotify = function (status, ready) {
var deferred = promise();
var config = exports.getConfig();
if (config.systemd) {
logger.debug("Sending ready notification to systemd");
logger.debug("NOTIFY_SOCKET=",process.env.NOTIFY_SOCKET)
sd.notify('READY=1');
deferred.resolve();
}
return deferred.promise;
}
exports.getRunDir = function () {
// the run dir where we can find init.yml is in env VCC_RUN_DIR
var run_dir = process.env['VCC_RUN_DIR'];
if (!run_dir) {
logger.warn('No environment variable VCC_RUN_DIR.... assuming /run');
run_dir = '/run';
}
return run_dir;
}
exports.getConfig = function (full, run_dir) {
if (!run_dir) {
var run_dir = exports.getRunDir();
}
return yaml.load(path.join(run_dir, 'cluster.yml'));
}
exports.writeConfig = function (newconfig) {
var deferred = promise();
var run_dir = exports.getRunDir();
fs.writeFile(path.join(run_dir, 'cluster.yml'), yaml.stringify(newconfig), function (err) {
if (err) {
deferred.reject(err);
}
deferred.resolve();
});
return deferred.promise;
}