sync/index.js

80 lines
2.9 KiB
JavaScript
Raw Normal View History

try {
var Server = require("./lib/server");
} catch (err) {
console.error('FATAL: Failed to require() lib/server.js');
if (/module version mismatch/i.test(err.message)) {
console.error('Module version mismatch, try running `npm rebuild` or removing ' +
'the node_modules folder and re-running `npm install`');
} else {
console.error('Possible causes:\n' +
' * You haven\'t run `npm run build-server` to regenerate ' +
'the runtime\n' +
' * You\'ve upgraded node/npm and haven\'t rebuilt dependencies ' +
'(try `npm rebuild` or `rm -rf node_modules && npm install`)\n' +
' * A dependency failed to install correctly (check the output ' +
'of `npm install` next time)');
}
2015-10-27 05:56:53 +00:00
console.error(err.stack);
process.exit(1);
}
2013-10-11 20:48:01 +00:00
var Config = require("./lib/config");
2013-10-11 21:31:40 +00:00
var Logger = require("./lib/logger");
const Switches = require("./lib/switches");
require("source-map-support").install();
2013-10-11 20:48:01 +00:00
2014-01-22 23:11:26 +00:00
Config.load("config.yaml");
var sv = Server.init();
if (!Config.get("debug")) {
process.on("uncaughtException", function (err) {
Logger.errlog.log("[SEVERE] Uncaught Exception: " + err);
Logger.errlog.log(err.stack);
});
2013-10-11 20:48:01 +00:00
2014-01-22 23:11:26 +00:00
process.on("SIGINT", function () {
sv.shutdown();
});
}
var stdinbuf = "";
process.stdin.on("data", function (data) {
stdinbuf += data;
if (stdinbuf.indexOf("\n") !== -1) {
var line = stdinbuf.substring(0, stdinbuf.indexOf("\n"));
stdinbuf = stdinbuf.substring(stdinbuf.indexOf("\n") + 1);
handleLine(line);
}
});
function handleLine(line) {
if (line === "/reload") {
Logger.syslog.log("Reloading config");
Config.load("config.yaml");
} else if (line === "/gc") {
if (global && global.gc) {
Logger.syslog.log("Running GC");
global.gc();
} else {
Logger.syslog.log("Failed to invoke GC: node started without --expose-gc");
}
} else if (line === "/delete_old_tables") {
require("./lib/database/update").deleteOldChannelTables(function (err) {
if (!err) {
Logger.syslog.log("Deleted old channel tables");
}
});
} else if (line.indexOf("/switch") === 0) {
var args = line.split(" ");
args.shift();
if (args.length === 1) {
Logger.syslog.log("Switch " + args[0] + " is " +
(Switches.isActive(args[0]) ? "ON" : "OFF"));
} else if (args.length === 2) {
Switches.setActive(args[0], args[1].toLowerCase() === "on" ? true : false);
Logger.syslog.log("Switch " + args[0] + " is now " +
(Switches.isActive(args[0]) ? "ON" : "OFF"));
}
2016-06-09 05:54:16 +00:00
} else if (line.indexOf("/reload-partitions") === 0) {
sv.reloadPartitionMap();
}
}