Skip to content
Browse files

[refactor test dist] Refactor /lib/foreverd/ into /lib/forever/service/

  • Loading branch information...
1 parent 36e0b9b commit 89be2521f07f1825926a3e061498bad36aad98c3 @indexzero committed Oct 8, 2011
View
2 examples/count-timer.js
@@ -1,7 +1,7 @@
/*
* count-timer.js: Counts forever on a timer
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
View
2 examples/error-on-timer.js
@@ -1,7 +1,7 @@
/*
* error-on-timer.js: Sample script that errors on a timer
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
View
2 examples/spawn-and-error.js
@@ -1,7 +1,7 @@
/*
* spawn-and-error.js: Sample script that spawns a simple child process and errors
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
View
7 lib/forever.js
@@ -50,6 +50,13 @@ forever.cli = require('./forever/cli');
require('pkginfo')(module, 'version');
//
+// Expose the global forever service
+//
+forever.__defineGetter__('service', function () {
+ return require('./forever/service');
+});
+
+//
// ### function getSockets (sockPath, callback)
// #### @sockPath {string} Path in which to look for UNIX domain sockets
// #### @callback {function} Continuation to pass control to when complete
View
6 lib/foreverd/adapter.js → lib/forever/service/adapters/adapter.js
@@ -7,13 +7,13 @@ var Adapter = module.exports = function Adapter(service) {
// This should install assets to appropriate places for initialization,
// configuration, and storage
//
-// The script will be used on startup to load ForeverService
+// The script will be used on startup to load Service
//
-// ForeverService should listen on something that the management events
+// Service should listen on something that the management events
// can respond to in full duplex
//
// The installed adapter should send the following events in dnode protocol
-// to the ForeverService and invoke methods as appropriate
+// to the Service and invoke methods as appropriate
//
Adapter.prototype.install = function install() {
throw new Error('not implemented');
View
0 lib/foreverd/adapter/init.d/index.js → lib/forever/service/adapters/initd/index.js
File renamed without changes.
View
0 lib/foreverd/adapter/systemv/foreverd → ...forever/service/adapters/systemv/foreverd
File renamed without changes.
View
4 lib/foreverd/adapter/systemv/index.js → ...forever/service/adapters/systemv/index.js
@@ -4,8 +4,8 @@ var fs = require('fs'),
spawn = require('child_process').spawn,
daemon = require('daemon'),
dnode = require('dnode'),
- forever = require('../../../forever'),
- Adapter = require('../../adapter');
+ forever = require('../../../../forever'),
+ Adapter = require('../adapter');
//
// Classic init.d script adapter
View
5 lib/foreverd/cli.js → lib/forever/service/cli.js
@@ -1,6 +1,6 @@
var optimist = require('optimist'),
forever = require('../forever'),
- ForeverService = require('./service'),
+ Service = require('./service'),
argv;
var mappings = {
@@ -31,7 +31,7 @@ function processArgs(cmd) {
var router = module.exports = function router(app) {
app.use(function (cmd, tty, next) {
cmd.flags._.shift();
- cmd.service = new ForeverService({
+ cmd.service = new Service({
adapter: cmd.flags.adapter
});
@@ -194,6 +194,7 @@ var router = module.exports = function router(app) {
app.cli('/pause', function (cmd, tty) {
cmd.service.pause();
});
+
app.cli('/resume', function (cmd, tty) {
cmd.service.resume();
});
View
15 lib/forever/service/index.js
@@ -0,0 +1,15 @@
+
+var fs = require('fs'),
+ path = require('path');
+
+var service = exports;
+
+service.Service = require('./service');
+service.adapters = {};
+
+fs.readdirSync(path.join(__dirname, 'adapters')).forEach(function (file) {
+ file = file.replace(/\.js/, '');
+ service.adapters.__defineGetter__(file, function () {
+ return require(__dirname + '/adapters/' + file);
+ })
+});
View
45 lib/foreverd/service.js → lib/forever/service/service.js
@@ -1,16 +1,15 @@
var fs = require('fs'),
path = require('path'),
util = require('util'),
+ events = require('events'),
dnode = require('dnode'),
- EventEmitter2 = require('eventemitter2').EventEmitter2,
portfinder = require('portfinder'),
- forever = require('../forever'),
- SystemVAdapter = require('./adapter/systemv');
-
+ forever = require('../../forever'),
+ SystemVAdapter = require('./adapters/systemv');
// options
// directories {log, pid, conf, run, local}
-var ForeverService = module.exports = function ForeverService(options) {
+var Service = module.exports = function Service(options) {
EventEmitter2.call(this);
options = options || {};
@@ -27,21 +26,17 @@ var ForeverService = module.exports = function ForeverService(options) {
this.servers = [];
if (typeof options.adapter === 'string') {
- options.adapter = ForeverService.adapter[options.adapter];
+ options.adapter = Service.adapter[options.adapter];
}
AdapterType = options.adapter || SystemVAdapter;
this.adapter = new AdapterType(this);
console.log(this.adapter);
};
-util.inherits(ForeverService, EventEmitter2);
-
-fs.readdirSync(path.join(__dirname, 'adapter')).forEach(function loadAdapter(adapterModule) {
- ForeverService[adapterModule] = require(path.join(__dirname, 'adapter', adapterModule));
-});
+util.inherits(Service, events.EventEmitter);
-ForeverService.prototype.startServer = function startServer(callback) {
+Service.prototype.startServer = function startServer(callback) {
var socket = path.join(forever.config.get('sockPath'), 'forever.sock'),
monitors = [],
self = this,
@@ -80,7 +75,7 @@ ForeverService.prototype.startServer = function startServer(callback) {
return this;
};
-ForeverService.prototype.listen = function listen(server) {
+Service.prototype.listen = function listen(server) {
var dnodeServer = dnode(this);
this.servers.push(dnodeServer);
@@ -93,7 +88,7 @@ ForeverService.prototype.listen = function listen(server) {
return this;
};
-ForeverService.prototype.load = function load() {
+Service.prototype.load = function load() {
var self = this;
this.adapter.load(function onLoaded(applications) {
console.error(arguments);
@@ -119,7 +114,7 @@ ForeverService.prototype.load = function load() {
// DOES NOT START THE APPLICATION
// call's the service manager's add method
//
-ForeverService.prototype.add = function add(file, options, callback) {
+Service.prototype.add = function add(file, options, callback) {
console.log(arguments);
if (this.paused) {
return callback && callback(new Error('foreverd is paused'));
@@ -133,7 +128,7 @@ ForeverService.prototype.add = function add(file, options, callback) {
// remove the application from the service manager
// call's the service manager's remove method
//
-ForeverService.prototype.remove = function remove(file, options, callback) {
+Service.prototype.remove = function remove(file, options, callback) {
if (this.paused) {
return callback(new Error('foreverd is paused'));
}
@@ -177,7 +172,7 @@ ForeverService.prototype.remove = function remove(file, options, callback) {
// installs all the required to run foreverd
// call's the service manager's install(options)
//
-ForeverService.prototype.install = function install(callback) {
+Service.prototype.install = function install(callback) {
this.adapter.install(callback);
return this;
};
@@ -187,7 +182,7 @@ ForeverService.prototype.install = function install(callback) {
// uninstalls all the required to run foreverd
// call's the service manager's uninstall(options)
//
-ForeverService.prototype.uninstall = function uninstall(callback) {
+Service.prototype.uninstall = function uninstall(callback) {
this.adapter.uninstall(callback);
return this;
};
@@ -196,7 +191,7 @@ ForeverService.prototype.uninstall = function uninstall(callback) {
// Function start()
// calls the appropriate OS functionality to start this service
//
-ForeverService.prototype.start = function start(callback) {
+Service.prototype.start = function start(callback) {
this.adapter.start(callback);
return this;
};
@@ -205,7 +200,7 @@ ForeverService.prototype.start = function start(callback) {
// Function run()
// creates monitors for all the services
//
-ForeverService.prototype.run = function run(callback) {
+Service.prototype.run = function run(callback) {
var self = this;
this.adapter.run(function adapterStarted() {
console.error(self.applications);
@@ -224,7 +219,7 @@ ForeverService.prototype.run = function run(callback) {
//
// Function stop(monitors)
//
-ForeverService.prototype.stop = function stop(callback) {
+Service.prototype.stop = function stop(callback) {
var self = this;
this.adapter.start(function adapterStopped() {
self.applications.forEach(function stopApplication(application) {
@@ -240,7 +235,7 @@ ForeverService.prototype.stop = function stop(callback) {
//
// Function restart()
//
-ForeverService.prototype.restart = function restart(callback) {
+Service.prototype.restart = function restart(callback) {
var self = this;
this.adapter.start(function adapterRestarted() {
self.applications.forEach(function restartApplication(application) {
@@ -257,7 +252,7 @@ ForeverService.prototype.restart = function restart(callback) {
// Function pause()
// disables adding / removing applications
//
-ForeverService.prototype.pause = function pause(callback) {
+Service.prototype.pause = function pause(callback) {
this.paused = true;
if (callback) {
callback();
@@ -270,7 +265,7 @@ ForeverService.prototype.pause = function pause(callback) {
// Function resume()
// reenables adding / removing applications
//
-ForeverService.prototype.resume = function resume(callback) {
+Service.prototype.resume = function resume(callback) {
this.paused = false;
if (callback) {
callback();
@@ -279,7 +274,7 @@ ForeverService.prototype.resume = function resume(callback) {
return this;
};
-ForeverService.prototype.list = function list(callback) {
+Service.prototype.list = function list(callback) {
this.adapter.list(callback);
return this;
};
View
1 package.json
@@ -32,7 +32,6 @@
"dnode": "0.8.x",
"eyes": "0.1.x",
"daemon": "0.3.x",
- "eventemitter2": "0.4.x",
"mkdirp": "0.x.x",
"nconf": "0.x.x",
"optimist": "0.2.x",
View
2 test/env-spawn-test.js
@@ -1,7 +1,7 @@
/*
* env-spawn-test.js: Tests for supporting environment variables in the forever module
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
View
2 test/fixtures/test-hook.js
@@ -1,7 +1,7 @@
/*
* test-hook.js: Test hook fixture for raising an event on forever.Monitor `exit`
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
View
2 test/forever-test.js
@@ -1,7 +1,7 @@
/*
* forever-test.js: Tests for forever module
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
View
2 test/helpers.js
@@ -1,7 +1,7 @@
/*
* helpers.js: Test helpers for the forever module
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
View
2 test/hook-test.js
@@ -1,7 +1,7 @@
/*
* hook-test.js: Tests for forever-based hooks
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
View
2 test/multiple-processes-test.js
@@ -1,7 +1,7 @@
/*
* forever-test.js: Tests for forever module
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/
View
25 test/service-test.js
@@ -0,0 +1,25 @@
+/*
+ * forever-test.js: Tests for forever module
+ *
+ * (C) 2010 Charlie Robbins
+ * MIT LICENCE
+ *
+ */
+
+var assert = require('assert'),
+ path = require('path'),
+ vows = require('vows'),
+ forever = require('../lib/forever');
+
+vows.describe('forever/service').addBatch({
+ "When using forever": {
+ "the service module": {
+ "should have the correct exports": function () {
+ assert.isObject(forever.service);
+ assert.isFunction(forever.service.Service);
+ assert.isObject(forever.service.adapters);
+ assert.isFunction(forever.service.adapters.initd)
+ }
+ }
+ }
+}).export(module);
View
4 test/spin-test.js
@@ -1,7 +1,7 @@
/*
- * forever-test.js: Tests for forever module
+ * spin-test.js: Tests for spin restarts in forever.
*
- * (C) 2010 and Charlie Robbins
+ * (C) 2010 Charlie Robbins
* MIT LICENCE
*
*/

0 comments on commit 89be252

Please sign in to comment.
Something went wrong with that request. Please try again.