mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
From the iojs docs: > An unhandled exception means your application - and by extension io.js itself - > is in an undefined state. Blindly resuming means anything could happen. > > Think of resuming as pulling the power cord when you are upgrading your system. > Nine out of ten times nothing happens - but the 10th time, your system is bust. > > uncaughtException should be used to perform synchronous cleanup before shutting > down the process. It is not safe to resume normal operation after > uncaughtException. If you do use it, restart your application after every > unhandled exception!
26 lines
778 B
JavaScript
26 lines
778 B
JavaScript
var logging = require("./lib/logging");
|
|
var cleaner = require("./lib/cleaner");
|
|
var config = require("./config");
|
|
var cluster = require("cluster");
|
|
|
|
process.on("uncaughtException", function(err) {
|
|
logging.error("uncaughtException", err.stack || err.toString());
|
|
process.exit(1);
|
|
});
|
|
|
|
if (cluster.isMaster) {
|
|
var cores = config.server.clusters || require("os").cpus().length;
|
|
logging.log("Starting", cores + " worker" + (cores > 1 ? "s" : ""));
|
|
for (var i = 0; i < cores; i++) {
|
|
cluster.fork();
|
|
}
|
|
|
|
cluster.on("exit", function (worker) {
|
|
logging.error("Worker #" + worker.id + " died. Rebooting a new one.");
|
|
setTimeout(cluster.fork, 100);
|
|
});
|
|
|
|
setInterval(cleaner.run, config.cleaner.interval * 1000);
|
|
} else {
|
|
require("./lib/server.js").boot();
|
|
} |