Skip to content

Commit

Permalink
Fix cluster subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
richtera committed Oct 13, 2012
1 parent 8d7de6f commit 6da7770
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 153 deletions.
6 changes: 5 additions & 1 deletion app-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ var rootpath = process.cwd() + '/',

var argv = processArgs();

launchServer();
if (module.parent)
module.exports.launchServer = launchServer;
else
launchServer();

/**
* Launch server instance, initially master, then each worker instance is forked.
Expand All @@ -43,6 +46,7 @@ function launchServer() {
config.init();

// Print the logo
console.log("ismaster!!!!");
logo.print();

// Set the number of workers
Expand Down
8 changes: 3 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ var path = rootpath,
* Any of these can be added into the by environment configuration files to
* enable modification by env.
*/
function bootApplication(next) {
function bootApplication(cluster, next) {

// Create our express instance, export for later reference
var app = express();
app.path = function() { return path };
app.isCluster = false;
app.isCluster = cluster;

// Load configuration
var Config = calipso.configuration; //require(path + "/lib/core/Config").Config;
Expand Down Expand Up @@ -275,8 +275,6 @@ function bootApplication(next) {

app.use(everyauth.middleware());

console.log(calipso.auth);

// Load placeholder, replaced later
if(app.config.get('libraries:stylus:enable')) {
console.log('enabling stylus');
Expand Down Expand Up @@ -336,7 +334,7 @@ function bootApplication(next) {
exports.boot = function (cluster, next) {

// Bootstrap application
bootApplication(next);
bootApplication(cluster, next);

};

Expand Down
132 changes: 0 additions & 132 deletions cluster.js

This file was deleted.

46 changes: 31 additions & 15 deletions lib/calipso-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ var fs = require('fs'),
nodepath = require('path'),
exec = require('child_process').exec,
logo = require('../logo'),
colors = require('colors');
colors = require('colors'),
cluster = null;
try {
cluster = require('cluster');
}
catch (e) {
}

/**
* Optimist configuration
Expand Down Expand Up @@ -56,29 +62,32 @@ runLauncher(appLauncher);
* @param appLauncher
*/
function runLauncher(appLauncher) {
if (cluster && cluster.isMaster) {
// Always use current directory?
console.log('Launching calipso from: '.cyan.bold + path.white);
console.log('Calipso directory: '.cyan.bold + calipsoPath.white);

// Check if this is a calipso src folder
if(isLibrary() && !appLauncher.src) {
console.log('\r\nWARNING:'.yellow.bold + ' You are running this from a Calipso source folder.'.white.bold);
}

// Always use current directory?
console.log('Launching calipso from: '.cyan.bold + path.white);
console.log('Calipso directory: '.cyan.bold + calipsoPath.white);

// Check if this is a calipso src folder
if(isLibrary() && !appLauncher.src) {
console.log('\r\nWARNING:'.yellow.bold + ' You are running this from a Calipso source folder.'.white.bold);
}

// Check if this is a calipso site
if(!isCalipso() && appLauncher.command != 'site' && !isLibrary()) {
console.log('\x1b[1mThis is not a Calipso site - you must run:\x1b[0m calipso site SiteName\r\n');
return;
// Check if this is a calipso site
if(!isCalipso() && appLauncher.command != 'site' && !isLibrary()) {
console.log('\x1b[1mThis is not a Calipso site - you must run:\x1b[0m calipso site SiteName\r\n');
return;
}
}

switch(appLauncher.command) {
case 'test':
runTests(appLauncher.script);
break;
case 'server':
runServer(appLauncher.server.port);
break;
case 'cluster':
runCluster(appLauncher.server.port);
break;
case 'site':
createApplication(path,appLauncher.script.params);
break;
Expand Down Expand Up @@ -165,6 +174,13 @@ function runTests(appLauncher) {

}

function runCluster(port) {

// Ensure we run in the local folder of the application
process.chdir(path);
require(path + '/app-cluster').launchServer();
}

/**
* Launch a server
*/
Expand Down

0 comments on commit 6da7770

Please sign in to comment.