-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmonitor.js
77 lines (65 loc) · 2.76 KB
/
monitor.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
// monitor.js (c) 2010-2014 Loren West and other contributors
// May be freely distributed under the MIT license.
// For further details and documentation:
// http://github.com/lorenwest/monitor-dashboard
(function(root){
// Load dependencies
var Monitor = require('./lib/index'),
Server = Monitor.Server,
UI = Monitor.UI,
UIServer = UI.Server,
OS = require('os');
/**
* Entry point into the monitor UI server application
*
* This is the module loaded and run by Node.js on program start.
* It bootstraps the node.js dashboard server.
*/
// Display the logo
console.log("");
console.log(" _________ __________");
console.log("___________________ /____ _______ ___________________(_)_ /______________");
console.log("__ __ \\ __ \\ __ /_ _ \\ __ __ `__ \\ __ \\_ __ \\_ /_ __/ __ \\_ ___/");
console.log("_ / / / /_/ / /_/ / / __/ _ / / / / / /_/ / / / / / / /_ / /_/ / /");
console.log("/_/ /_/\\____/\\__,_/ \\___/ /_/ /_/ /_/\\____//_/ /_//_/ \\__/ \\____//_/");
console.log("");
// Output an application template
if (process.argv.length > 3 && process.argv[2] === '--app') {
require('./lib/js/AppTemplate');
process.exit(0);
}
// Boot the UI server.
// This accepts http and websocket connections on the configured port.
var uiServer = new UIServer();
uiServer.start(function() {
// If the host can connect from any IP address (INADDR_ANY), display the DNS hostname
var connectTo = Monitor.Config.Dashboard.allowExternalConnections ? OS.hostname() : 'localhost';
console.log("Now showing at http://" + connectTo + ":" + uiServer.get('port') + "/");
// Output security concerns
if (!Monitor.Config.Dashboard.allowExternalConnections) {
console.log("");
console.log("External connections disabled.");
console.log("See " + process.cwd() + "/config/external.js for more information.");
}
});
// Boot another Monitor server for accepting websocket connections
// on the standard Monitor port range.
var server = new Server();
server.start();
// Process uncaught exceptions.
process.on('uncaughtException', function(err){
// On laptop sleep/startup the DNS servers aren't immediately available,
// resulting in a flood of these for socket.io until DNS services are back up.
if (err.message === 'ECONNREFUSED, Could not contact DNS servers') {
return;
}
// Don't allow the process to continue in an unknown state.
console.error("Uncaught Exception: " + err.message);
console.error(err.stack);
uiServer.stop(function(){
process.exit(1);
});
// Don't wait around if the server is hung.
setTimeout(function(){process.exit(1);}, 2000);
});
}(this));