conf.group = "";
+// Log file location
+conf.log = "kiwi.log";
+
+
// Server listen blocks
conf.servers = [];
--- /dev/null
+var kiwi_app = './server/kiwi.js';\r
+\r
+\r
+var daemon = require('daemonize2').setup({\r
+ main: kiwi_app,\r
+ name: 'kiwiirc',\r
+ pidfile: 'kiwiirc.pid'\r
+});\r
+\r
+switch (process.argv[2]) {\r
+ case '-f':\r
+ require(kiwi_app);\r
+ break;\r
+\r
+ case 'start':\r
+ daemon.start();\r
+ break;\r
+\r
+ case 'stop':\r
+ daemon.stop();\r
+ break;\r
+\r
+ case 'restart':\r
+ daemon.stop(function(err) {\r
+ daemon.start();\r
+ });\r
+ break;\r
+\r
+ case 'status':\r
+ var pid = daemon.status();\r
+ if (pid)\r
+ console.log('Daemon running. PID: ' + pid);\r
+ else\r
+ console.log('Daemon is not running.');\r
+ break;\r
+\r
+\r
+ default:\r
+ console.log('Usage: [-f|start|stop|restart|status]');\r
+}
\ No newline at end of file
"node-static": "0.5.9",\r
"uglify-js": "1.2.3",\r
"socket.io": "0.8.7",\r
- "underscore": "1.3.3"\r
+ "underscore": "1.3.3",\r
+ "daemonize2": "0.4.0-rc.5"\r
}\r
}
\ No newline at end of file
var fs = require('fs');
var config_filename = 'config.js',
- config_dirs = ['/etc/kiwiirc/', __dirname + '/'],
+ config_dirs = ['/etc/kiwiirc/', __dirname + '/../'],
environment = 'production',
- loaded_config = Object.create(null);
+ loaded_config = Object.create(null);
function loadConfig() {
// Try load the new config file
new_config = require(conf_filepath);
- console.log('Loaded config file ' + config_dirs[i] + config_filename);
break;
}
} catch (e) {
}
if (new_config) {
- loaded_config = new_config;
- return loaded_config;
+ loaded_config = new_config;
+ return loaded_config;
} else {
- return false;
+ return false;
}
}
module.exports.setEnvironment = function (new_environment) {
- environment = new_environment;
+ environment = new_environment;
};
// Get the current config. Optionally for a different environment than currently set
module.exports.get = function (specific_environment) {
- specific_environment = specific_environment || environment;
-
- return loaded_config[specific_environment];
+ specific_environment = specific_environment || environment;
+
+ return loaded_config[specific_environment];
};
module.exports.loadConfig = loadConfig;
\ No newline at end of file
+process.chdir(__dirname + '/../');
+config.loadConfig();
+
+
+// If we're not running in the forground and we have a log file.. switch
+// console.log to output to a file
+if (process.argv.indexOf('-f') === -1 && config.get().log) {
+ (function () {
+ var log_file_name = config.get().log;
+
+ if (log_file_name[0] !== '/') {
+ log_file_name = __dirname + '/../' + log_file_name;
+ }
+
+
+
+ console.log = function() {
+ var logfile = fs.openSync(log_file_name, 'a'),
+ out;
+
+ out = Array.prototype.join.apply(arguments, [' ']);
+
+ // Make sure we out somthing to log and we have an open file
+ if (!out || !logfile) return;
+
+ out += '\n';
+ fs.writeSync(logfile, out, null);
+
+ fs.closeSync(logfile);
+ };
+ })();
+}
-config.loadConfig();
// Make sure we have a valid config file and at least 1 server
if (Object.keys(config.get()).length === 0) {
console.log('Listening on ' + web_config.address + ':' + web_config.port.toString() + ' without SSL');
}
- this.ws.set('log level', 1);
+ this.ws.set('log level', 0);
+ this.ws.set('log color', false);
this.ws.enable('browser client minification');
this.ws.enable('browser client etag');
this.ws.set('transports', transports);