forked from adminion/off-the-record
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (36 loc) · 1.2 KB
/
server.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
#!/usr/local/bin/node
process.env.OTR_PREFIX = __dirname;
var OffTheRecord = require('./lib/'),
interrupt,
server,
stopping;
// if (process)
Error.stackTraceLimit = Infinity;
server = new OffTheRecord();
var debug = require('debug')(server.env().context());
process.on('SIGINT', function () {
// if we're not already stopping
if (!stopping) {
// if interrupt is truthy (the user has pressed ^C within the last second)
// then shutdown the server
if (interrupt) {
// set the stopping flag to true to indicate that the server is stopping (in case another SIGINT is sent)
stopping = true;
console.log('\nstopping server...');
// tell the server to stop itself.
server.stop(function () {
console.log('server stopped.');
// process.exit();
});
// if interrupt is not truthy
} else {
// set interrupt to the ID of the timeout that sets interrupt to undefined after 1 second
interrupt = setTimeout(function () {
interrupt = undefined;
}, 1000);
console.log('\n(^C again to quit)');
}
}
});
console.log('starting %s v%s...', server.env().package.name, server.env().package.version);
server.start();