-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
121 lines (89 loc) · 2.46 KB
/
Copy pathmain.js
File metadata and controls
121 lines (89 loc) · 2.46 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Copyright (c) 2014, Joyent, Inc.
* Copyright (c) 2016, Les Technologies Alesium, Inc.
*/
var assert = require('assert');
var crypto = require('crypto');
var fs = require('fs');
var path = require('path');
var cluster = require('cluster');
var os = require('os');
var Logger = require('bunyan');
var nopt = require('nopt');
var ufds = require('./lib/sql_ldap');
// TODO: groups
// --- Globals
var LOG = new Logger({
name: 'sql_ldap',
stream: process.stdout,
serializers: {
err: Logger.stdSerializers.err
}
});
var OPTS = {
'debug': Number,
'file': String,
'port': Number,
'help': Boolean,
'single': Boolean
};
var SHORT_OPTS = {
'd': ['--debug'],
'f': ['--file'],
'p': ['--port'],
's': ['--single'],
'h': ['--help']
};
// --- Helpers
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/sql_ldap.config.json';
if (parsed.help) {
usage(0);
}
LOG.info({file: file}, 'Processing configuration file');
_config = sql-ldap.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 = sql_ldap.createServer(config);
server.init(function () {
return (true);
});