-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
100 lines (74 loc) · 2.05 KB
/
main.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var assert = require('assert');
var crypto = require('crypto');
var fs = require('fs');
var path = require('path');
var os = require('os');
var Logger = require('bunyan');
var nopt = require('nopt');
var ldapMysql = require('./lib/ldapjs-mysql');
var LOG = new Logger({
name: 'ldapjs-mysql',
stream: process.stdout,
serializers: {
err: Logger.stdSerializers.err
}
});
var OPTS = {
'debug': Number,
'file': String,
'port': Number,
'help': Boolean,
};
var SHORT_OPTS = {
'd': ['--debug'],
'f': ['--file'],
'p': ['--port'],
'h': ['--help']
};
function usage(code, message) {
var _opts = '', msg;
Object.keys(SHORT_OPTS).forEach(function (k) {
var longOpt = SHORT_OPTS[k][0].replace('--', ''),
type = OPTS[longOpt].name || 'string';
if (type && type === 'boolean') {
type = '';
}
type = type.toLowerCase();
_opts += ' [--' + longOpt + ' ' + type + ']';
});
msg = (message ? message + '\n' : '') +
'usage: ' + path.basename(process.argv[1]) + _opts;
console.error(msg);
process.exit(code);
}
function processConfig() {
var _config,
parsed = nopt(OPTS, SHORT_OPTS, process.argv, 2),
file = parsed.file || __dirname + '/etc/ldapjs-mysql.config.json';
if (parsed.help) {
usage(0);
}
LOG.info({file: file}, 'Processing configuration file');
_config = ldapjsMysql.processConfigFile(file);
if (parsed.port) {
_config.port = parsed.port;
}
if (parsed.debug) {
LOG.level(parsed.debug > 1 ? 'trace' : 'debug');
}
if (_config.logLevel) {
LOG.level(_config.logLevel);
}
_config.single = (parsed.single) ? true : false;
LOG.debug('config processed: %j', _config);
_config.log = LOG;
return _config;
}
// --- Mainline
var config = processConfig();
// CAPI-169: Clustering intentionally disabled due to race condition on
// ldif bootstrap.
var server = ldapMysql.createServer(config);
server.init(function () {
return (true);
});