Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Unicorn for node.js
JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
src
.gitignore
README.markdown
package.json
wscript

README.markdown

Multiple node server instance manager with Unicorn-like features

Heavily inspired by Spark and Unicorn

Features:

  • Supports any type of Node.js server as long as it inherits from net.Server (http.Server, connect.Server, ...).
  • Failover - when a worker dies it is restarted.
  • Zero downtime app reload.
  • Set gid, uid.
  • Set working dir.
  • Redirect stdout to log files for master / workers
  • daemonize properly.

Install:

nmp install fugue

Usage:

Example:

var fugue = require('fugue'),
    net =   require('net');

var server = net.createServer(function(conn) {
  conn.end(process.pid.toString() + "Hello from worker "+fugue.workerId());
});

fugue.start(server, 4000, null, 2, {verbose : true});

Having trouble? read the FAQ.

fugue.start

For UNIX sockets:

fugue.start(server, socket_path, number_of_workers, options);

For TCP:

fugue.start(server, port, host, number_of_workers, options);

Options on fugue.start:

  • working_path : absolute path for the working dir
  • tmp_path : the absolute path for the temp dir. defaults to current_dir/tmp
  • log_file : the full path of the log file if you wish stdout to be redirected there. All workers + master will write here. If absent does not touch stdout.
  • master_log_file : alternative path for the log file for the master only.
  • uid : unix user id for workers. Defaults to current user
  • gid : unix group id for workers. Defaults to current group
  • daemonize : to fork and detach
  • master_pid_path : master PID file path. If not passed in, no pid file is written.

How to reload

You can reload the entire app (with no downtime) For now, you will have to find the PID of the master and, on the command line:

kill -USR2 <PID>

That will reload your service with no downtime.

Read more on how this works.

TODO:

  1. (DONE) Save the PID of the master into a file. This can be tricky when handling master restarts. Should lock?
  2. (DONE) Don't kill slaves with open connections.
  3. Use fork() to start the workers instead of spawn
  4. unit / integration tests - any ideas on how to test fugue?
  5. review the master / worker protocol for passing in the server socket
  6. review the code that synchronously tries to fetch the file descriptor from the original master into the new respawned master (lib/fugue.js lines 72 - 91) - they're a bit too hacky - try and remove the recvMsg cycle...
  7. Monitor request timeouts (as Unicorn does) - only plausible for HTTP Servers, though (??)
  8. (DONE) Don't hardcode path for unix socket. Make it a temporary random file and pass it around on environment?
  9. Somehow delete master sockets that are not being used. This can be tricky, since master socket paths are passed around to workers and new masters.
Something went wrong with that request. Please try again.