Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bin files replaced, console introduced

commit 10b3d98aa4730bdb0f083d1570d04bb44c6ae229 1 parent b7dfbca
@dimsmol authored
View
3  bin/apidaemon
@@ -1,3 +0,0 @@
-#!/usr/bin/env node
-"use strict";
-require('../lib/loader').create().getApp({ isDaemon: true }).start();
View
3  bin/apirun
@@ -1,3 +0,0 @@
-#!/usr/bin/env node
-"use strict";
-require('../lib/loader').create().getApp().start();
View
3  bin/apis
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+"use strict";
+require('../lib/loader').run();
View
3  bin/apistart
@@ -1,3 +0,0 @@
-#!/usr/bin/env node
-"use strict";
-require('../lib/loader').create().getDaemonMaster().start();
View
3  bin/apistop
@@ -1,3 +0,0 @@
-#!/usr/bin/env node
-"use strict";
-require('../lib/loader').create().getDaemonMaster().stop();
View
15 lib/app.js
@@ -14,12 +14,27 @@ App.prototype.addUnits = function () {
App.prototype.start = function () {
this.ensureInited();
+ this.socketsOn();
+ this.webStart();
+};
+
+App.prototype.socketsOn = function () {
if (!this.units.require('core.settings').core.socket.disabled) {
// give it chance to start
this.units.require('core.mechanics.socket');
}
+};
+
+App.prototype.webStart = function () {
this.units.require('core.mechanics.web').start();
};
+App.prototype.console = function () {
+ this.ensureInited();
+ global.app = this;
+ var repl = require('repl');
+ repl.start({ useGlobal: true });
+};
+
module.exports = App;
View
2  lib/daemon.js
@@ -152,7 +152,7 @@ Daemon.prototype.startFailed = function (err) {
};
Daemon.prototype.getStartExec = function () {
- return this.settings.start.exec || path.join(__dirname, '..', 'bin', 'apidaemon');
+ return this.settings.start.exec;
};
Daemon.prototype.getStartArgs = function () {
View
50 lib/loader.js
@@ -7,14 +7,52 @@ var Loader = function (opt_options) {
this.options = opt_options;
};
+Loader.prototype.commands = ['run', 'start', 'stop', 'worker', 'console'];
+
+Loader.prototype.run = function () {
+ var cmd = process.argv[2];
+ switch (cmd) {
+ case 'run':
+ this.getApp().start();
+ break;
+ case 'start':
+ this.getDaemonMaster().start();
+ break;
+ case 'stop':
+ this.getDaemonMaster().stop();
+ break;
+ case 'daemon':
+ this.getApp({ daemon: true }).start();
+ break;
+ case 'worker':
+ this.getWorker().start();
+ break;
+ case 'console':
+ this.getWorker().console();
+ break;
+ default:
+ this.printUsageAndExit();
+ }
+};
+
+Loader.prototype.printUsageAndExit = function () {
+ console.log('Usage:');
+ console.log('\t' + path.basename(process.argv[1]) + ' <command>');
+ console.log();
+ console.log('Supported commands:');
+ console.log('\t' + this.commands.join(' '));
+ process.exit(1);
+};
+
Loader.prototype.basePath = 'lib';
Loader.prototype.standardBasePath = __dirname;
-Loader.prototype.fileNames = {
+Loader.prototype.appFiles = {
loader: 'loader',
app: 'app',
clusterMaster: 'cluster_master',
- daemonMaster: 'daemon_master'
+ daemonMaster: 'daemon_master',
+ console: 'console'
};
Loader.prototype.standardUnitPaths = {
@@ -82,11 +120,11 @@ Loader.prototype.loadUnit = function (name) {
};
Loader.prototype.getPath = function (name) {
- return path.join(process.cwd(), this.basePath, this.fileNames[name]);
+ return path.join(process.cwd(), this.basePath, this.appFiles[name]);
};
Loader.prototype.getStandardPath = function (name) {
- return path.join(this.standardBasePath, this.fileNames[name]);
+ return path.join(this.standardBasePath, this.appFiles[name]);
};
Loader.prototype.tryRequire = function (id) {
@@ -157,5 +195,9 @@ Loader.create = function (opt_options) {
return new Loader(opt_options).getLoader(opt_options);
};
+Loader.run = function (opt_options) {
+ return Loader.create(opt_options).run();
+};
+
module.exports = Loader;
View
4 lib/settings.js
@@ -28,8 +28,8 @@ Settings.prototype.init = function () {
daemon: {
start: {
- exec: null,
- args: null,
+ exec: require.main.filename,
+ args: ['daemon'],
stdout: null,
stderr: null
},
View
10 package.json
@@ -28,8 +28,16 @@
"type": "git",
"url": "https://github.com/dimsmol/apis"
},
+ "bin": {
+ "apis": "./bin/apis"
+ },
"directories": {
- "lib": "./lib"
+ "lib": "./lib",
+ "bin": "./bin"
+ },
+ "scripts": {
+ "start": "node bin/apis start",
+ "stop": "node bin/apis stop",
},
"main": "./lib/index"
}
Please sign in to comment.
Something went wrong with that request. Please try again.