Permalink
Browse files

Release v0.0.14

  • Loading branch information...
1 parent 58417ff commit 72a682f166373d2dfae2f3b6b1ce47beb4417bd1 @pgte committed Oct 1, 2010
Showing with 29 additions and 16 deletions.
  1. +2 −0 .gitignore
  2. +3 −3 examples/test_app.js
  3. +23 −12 lib/fugue.js
  4. +1 −1 package.json
View
@@ -0,0 +1,2 @@
+.lock-wscript
+build
@@ -9,16 +9,16 @@ var fugue = require('../lib/fugue.js'),
var server = net.createServer(function(conn) {
//setTimeout(function() {
- conn.end(process.pid.toString() + "Hello from "+fugue.workerId()+". I am user " + process.getuid() + " on dir " + process.cwd());
+ conn.end("Hello from worker "+fugue.workerId()+".\nI am user " + process.getuid() + "\non dir " + process.cwd()+"\nPID: "+process.pid.toString() + "\n");
//}, 5000);
});
fugue.start(server, 4000, null, 2, {
//fugue.start(server, 'tmp/my_test_server.sock', 2, {
daemonize: false,
- //log_file: process.cwd() +'/log/children.txt',
- //master_log_file: process.cwd() +'/log/master.txt',
+ log_file: process.cwd() +'/log/children.txt',
+ master_log_file: process.cwd() +'/log/master.txt',
// uid: 'pedroteixeira',
// gid: 'staff',
working_path: '/tmp',
View
@@ -61,6 +61,11 @@ exports.start = function(server, port, host, worker_count, options) {
fs = require('fs'),
path = require('path'),
netBinding = process.binding('net');
+
+ // Redirect stdout and stderr
+ if (options.log_file) {
+ process.stdout.fd = fs.openSync(options.log_file, 'a');
+ }
// calculate master_socket_path.
// It can come from env if we have been spawned or we have to create a new one
@@ -77,13 +82,13 @@ exports.start = function(server, port, host, worker_count, options) {
log('Using master socket path: '+master_socket_path);
- // Redirect stdout and stderr
- if (options.log_file) {
- process.stdout.fd = fs.openSync(options.log_file, 'a');
- }
-
if (is_master) { // Master
+ // If we are respawned from another master we have to setsid anyway
+ if (process.env._FUGUE_ORIG_MASTER_PID) {
+ daemon = require(__dirname+'/../build/default/daemon');
+ daemon.setSid();
+ }
log('Starting new master...');
if (options.master_log_file) {
@@ -168,7 +173,7 @@ exports.start = function(server, port, host, worker_count, options) {
for(var i in process.env){
env[i] = process.env[i];
}
- env._FUGUE_WORKER = "" + worker_idx;
+ env._FUGUE_WORKER = "" + (worker_idx + 1);
var args = process.argv;
// spawn worker process
@@ -192,6 +197,7 @@ exports.start = function(server, port, host, worker_count, options) {
// fork workers
log('Spawning workers...');
+ process.env._FUGUE_WORKER_COUNT = worker_count;
for (var worker_idx = 0; worker_idx < worker_count; worker_idx ++) {
spawn_worker(worker_idx);
}
@@ -282,7 +288,15 @@ exports.start = function(server, port, host, worker_count, options) {
var connection = net.createConnection(master_socket_path).on('connect', function() {
connection.write('GIMME_SOCKET');
connection.on('fd', function(fd) {
- server.listenFD(fd);
+
+ var kill_master_pid = parseInt(process.env._FUGUE_ORIG_MASTER_PID);
+ // only the last worker tries to kill original master
+ if (!!kill_master_pid && workerId() == process.env._FUGUE_WORKER_COUNT) {
+ log('killing original master');
+ process.kill(kill_master_pid);
+ }
+
+ // change working dir
if (process.cwd() != options.working_path) {
process.chdir(options.working_path);
}
@@ -294,11 +308,8 @@ exports.start = function(server, port, host, worker_count, options) {
if(process.getuid() != options.uid) {
process.setuid(options.uid);
}
-
- var kill_master_pid = parseInt(process.env._FUGUE_ORIG_MASTER_PID);
- if (!!kill_master_pid && workerId() == 0) { // only the first worker tries to kill original master
- process.kill(kill_master_pid);
- }
+
+ server.listenFD(fd);
});
});
View
@@ -1,6 +1,6 @@
{ "name" : "fugue"
, "description" : "Unicorn for node for node"
-, "version" : "0.0.13"
+, "version" : "0.0.14"
, "homepage" : "http://www.metaduck.com/fugue"
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com> (http://www.metaduck.com)"
, "contributors" :

0 comments on commit 72a682f

Please sign in to comment.