Skip to content

Commit

Permalink
made auto restart call the call back only once
Browse files Browse the repository at this point in the history
  • Loading branch information
shimondoodkin committed Jul 22, 2010
1 parent 1c9f9e8 commit 791edb4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
25 changes: 20 additions & 5 deletions README.md
Expand Up @@ -105,8 +105,23 @@ It is basicly: nginx<->nodejs as an upstream.
also i added php-cgi to nginx to use moadmin.php - mongodb db editor.

### Multi Process
you can put nginx or haproxy as a front and create nodejs1.sh, nodejs2.sh,
nodejs3.sh, nodejs4.sh, and matching .conf files for the upstart.
Also you can have port as an argument to your server.js.
To achive best performance. it was found by testing
that the number of processors should much the number of cores not more not lest.
you can put nginx or haproxy as a front and create several .conf files for the upstart.

in each you modify the execution line to contain port number ex.:
in the nodejs1.conf
exec sudo -u www-data /bin/bash /var/www/nodejs-mongodb-app/nodejs.sh 8001
in the nodejs2.conf
exec sudo -u www-data /bin/bash /var/www/nodejs-mongodb-app/nodejs.sh 8002

and make port as an argument to your server.js.
//http.createServer(server_handler_function).listen(process.argv[2]||8001);
//see http://nodejs.org/api.html#process-argv-58
//process.argv.forEach(function (val, index, array) {
// console.log(index + ': ' + val);
//});

To achive best performance. it was found by testing (during development of twisted and nginx) that the number of processors should much the number of cores not more not lest.

### the idea behind the architecture
the idea is to add an extra level of fail-safety by using a stable system shell script to restart node instead of node itself.

7 changes: 5 additions & 2 deletions autoexit.js
Expand Up @@ -17,11 +17,14 @@

var fs = require('fs'); // allaws to open files
var sys = require('sys'); // allows to print errors to command line

this.restarted=false;
var that=this;

function watch(parse_file_list_dirname,extention,callback) {

var restart_server = function(file){
if(that.restarted) return;
that.restarted=true;
if(callback)callback();
sys.puts((new Date).toTimeString()+' change discovered, restarting server. the file was: '+file);
process.exit();
Expand Down Expand Up @@ -87,4 +90,4 @@ function watch(parse_file_list_dirname,extention,callback) {
this.watch=watch;


//////// end auto exit //////////////////////////
//////// end auto exit //////////////////////////

0 comments on commit 791edb4

Please sign in to comment.