Skip to content

Commit

Permalink
deploy script working
Browse files Browse the repository at this point in the history
  • Loading branch information
luiseduardobrito committed Sep 19, 2013
2 parents cd2605b + e49b804 commit 4289e93
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
11 changes: 9 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var pjson = require("./package.json");

var config = require("./config/general");
var socket_config = require("./config/general");

Expand All @@ -22,6 +24,8 @@ var Cluster = function(cluster) {

if (cluster.isMaster) {

log.info((pjson.name || "web cluster") + " > starting infrastructure...");

for (var i = 0; i < numCPUs; i++)
cluster.fork()

Expand All @@ -41,7 +45,7 @@ var Cluster = function(cluster) {
var server = new Server(function(server, app){
server.listen(app.get('port'), function(){
socket = new Socket(server);
log.info('Worker listening on port ' + app.get('port'));
log.info('worker listening on port ' + app.get('port'));
});
});
}
Expand All @@ -51,6 +55,9 @@ var Cluster = function(cluster) {

function init() {

if(!config[config.state])
throw new Error("No configuration state available");

var state = config[config.state];
numCPUs = state.cluster? state.cluster.max || numCPUs : numCPUs;

Expand All @@ -63,5 +70,5 @@ var Cluster = function(cluster) {
var cluster = new Cluster(cluster);

cluster.start(function(){
log.info("Starting cluster with " + cluster.cpus + " forks.\n")
log.info("starting cluster with " + cluster.cpus + " forks.\n")
});
4 changes: 2 additions & 2 deletions config/general.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
state: "development",

state: "production",

development: {

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"private": true,
"scripts": {
"start": "node app.js",
"deploy": "node scripts/deploy.js",
"stop": "node scripts/stopall.js",
"debug": "node-inspector --web-port=3333 & node --debug-brk app",
"test": "nodeunit tests/*",
"debug-test": "node-inspector --web-port=3333 & node --debug-brk `which nodeunit` tests/*",
Expand All @@ -19,7 +21,8 @@
"mongojs": "~0.7.17",
"async": "~0.2.9",
"express-ejs-layouts": "~0.3.1",
"ejs": "~0.8.4"
"ejs": "~0.8.4",
"forever": "~0.10.8"
},
"devDependencies": {
"nodeunit": "~0.8.1"
Expand Down
28 changes: 28 additions & 0 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/env node

//////////////////////////////////////////////
// //
// Node Web Cluster - Deployment Routines //
// //
//////////////////////////////////////////////

var forever = require("forever")
var path = require("path")
var log = require("winston")

try {

// fork and start
forever.startDaemon(path.resolve(__dirname, "../app.js"), {
logFile: path.resolve(__dirname, "../logs"),
logFile: path.resolve(__dirname, "../logs/pids"),
});

log.info("forever started successfully")
}
catch(e) {

// ooops
log.error("ooops, forever could not be launched!");
throw e;
}
22 changes: 22 additions & 0 deletions scripts/stopall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/env node

//////////////////////////////////////////////
// //
// Node Web Cluster - Deployment Routines //
// //
//////////////////////////////////////////////

var forever = require("forever");
var log = require("winston")

try {

log.info("stopping all forever forks")
forever.stopAll()
}
catch(e) {

// ooops
log.error("ooops, forever could not be stopped!");
throw e;
}

0 comments on commit 4289e93

Please sign in to comment.