-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathserver.js
More file actions
71 lines (54 loc) · 1.58 KB
/
Copy pathserver.js
File metadata and controls
71 lines (54 loc) · 1.58 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
'use strict';
process.title = 'pending-dns';
// cache before wild-config
const argv = process.argv.slice(2);
const config = require('wild-config');
const logger = require('./lib/logger').child({ component: 'server' });
const pathlib = require('path');
const { Worker, SHARE_ENV } = require('worker_threads');
const { isemail } = require('./lib/tools');
const { installCrashHandlers } = require('./lib/close-process');
if (!config.acme || !isemail(config.acme.email)) {
console.error('"acme.email" configuration value is not set or is not a valid email address');
process.exit(51);
}
require('./lib/sentry').initSentry('main');
const { isClosing } = installCrashHandlers(logger);
let workers = new Map();
let spawnWorker = type => {
if (isClosing()) {
return;
}
if (!workers.has(type)) {
workers.set(type, new Set());
}
let worker = new Worker(pathlib.join(__dirname, 'workers', `${type}.js`), {
argv,
env: SHARE_ENV
});
workers.get(type).add(worker);
worker.on('exit', exitCode => {
workers.get(type).delete(worker);
if (isClosing()) {
return;
}
// spawning a new worker trigger reassign
logger.error({ msg: 'Worker exited', exitCode });
setTimeout(() => spawnWorker(type), 1000);
});
};
if (config.api.enabled) {
spawnWorker('api');
}
// DNS server
if (config.dns.enabled) {
spawnWorker('dns');
}
// Public HTTP/HTTPS server
if (config.public.enabled) {
spawnWorker('public');
}
// Healthchecks
if (config.health.enabled) {
spawnWorker('health');
}