diff --git a/index.js b/index.js new file mode 100644 index 00000000..e288822a --- /dev/null +++ b/index.js @@ -0,0 +1,27 @@ +/* +The MIT License (MIT) +Copyright (c) 2013 Calvin Montgomery + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +var Server = require("./lib/server"); +var Config = require("./lib/config"); + +Config.load("cfg.json", function (cfg) { + var sv = Server.init(cfg); + if(!cfg["debug"]) { + process.on("uncaughtException", function (err) { + Logger.errlog.log("[SEVERE] Uncaught Exception: " + err); + Logger.errlog.log(err.stack); + }); + + process.on("SIGINT", function () { + sv.shutdown(); + }); + } +}); diff --git a/lib/config.js b/lib/config.js index aa29d9ec..89115522 100644 --- a/lib/config.js +++ b/lib/config.js @@ -62,7 +62,7 @@ function save(cfg, file) { fs.writeFileSync(file, JSON.stringify(x, null, 4)); } -exports.load = function (Server, file, callback) { +exports.load = function (file, callback) { var cfg = {}; for(var k in defaults) cfg[k] = defaults[k]; @@ -102,7 +102,6 @@ exports.load = function (Server, file, callback) { cfg["loaded"] = true; save(cfg, file); - Server.cfg = cfg; - callback(); + callback(cfg); }); } diff --git a/lib/server.js b/lib/server.js index fe27063f..dadc16c8 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,3 +1,14 @@ +/* +The MIT License (MIT) +Copyright (c) 2013 Calvin Montgomery + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + var path = require("path"); var fs = require("fs"); var http = require("http"); @@ -276,6 +287,16 @@ var singleton = null; module.exports = { init: function (cfg) { + Logger.syslog.log("Starting CyTube v" + VERSION); + var chanlogpath = path.join(__dirname, "../chanlogs"); + fs.exists(chanlogpath, function (exists) { + exists || fs.mkdir(chanlogpath); + }); + + var chandumppath = path.join(__dirname, "../chandump"); + fs.exists(chandumppath, function (exists) { + exists || fs.mkdir(chandumppath); + }); singleton = new Server(cfg); return singleton; }, @@ -284,29 +305,3 @@ module.exports = { return singleton; } }; - -Logger.syslog.log("Starting CyTube v" + VERSION); -var chanlogpath = path.join(__dirname, "../chanlogs"); -fs.exists(chanlogpath, function (exists) { - exists || fs.mkdir(chanlogpath); -}); - -var chandumppath = path.join(__dirname, "../chandump"); -fs.exists(chandumppath, function (exists) { - exists || fs.mkdir(chandumppath); -}); - -var x = {}; -Config.load(x, path.join(__dirname, "../cfg.json"), function () { - module.exports.init(x.cfg); - if(!singleton.cfg["debug"]) { - process.on("uncaughtException", function (err) { - Logger.errlog.log("[SEVERE] Uncaught Exception: " + err); - Logger.errlog.log(err.stack); - }); - - process.on("SIGINT", function () { - singleton.shutdown(); - }); - } -}); diff --git a/run.sh b/run.sh index ef2d896e..27b3caa1 100755 --- a/run.sh +++ b/run.sh @@ -2,7 +2,7 @@ while : do - node lib/server.js + node index.js sleep 2 done