1.3.0 • Published 7 years ago

pluribus v1.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Pluribus

Cluster manager for NodeJS. Pluribus allows you to run multiple workers, handles automatic respawns, graceful restarts and graceful shutdowns.

Pluribus accepts an option flag instructing it to watch for file changes in the directories you specify, during development.

Workers run with reduced privileges by default, and the number of workers is configurable (but defaults to the number of CPU cores).

Installation

Simple example

const pluribus = require("pluribus");

function worker() {
    console.log("I'm a worker");
}

function master() {
    console.log("I'm the master");
}

const options = {
    master: master,
    worker: worker,
    silent: false,
    privs: {user: "nobody", group: "nogroup"}
};

pluribus.execute("Example", options);

This example in use:

Killing and Restarting

Pluribus automatically spawns replacements for dead workers.

Watching for Changes and Manual Restart

If you send a --pluribus-watch flag to your application as a command line argument, it will watch for file changes in the directories specified in your configuration object. If you do not list any globs in your configuration, a default globs array will be used.

You can also watch for changes by including a watch: true property in your config object and running your application without the --pluribus-watch flag.

See the API documentation section of this readme for details of how to set up your configuration.

While watching for changes, you can manually restart your application by typing rs at the command line.

Specify a Custom Logger

If you provide a logging function in your configuration object, it will be used. For example, config.logger = require("winston").info.

API Documentation

Pluribus exports one method, called execute.

The execute method takes two arguments.

First is a string used for logging. Can be anything. We suggest the name of your app.

Second is a config object with the following format. All the values are optional, but the defaults may not suit you.

const config = {};

config.master = function () {};   // Function to execute as the master.
                                  //   Default: none defined

config.worker = function () {};   // Function to execute as the workers.
                                  //   Default: none defined
                                  //   (though optional, its kinda the whole point)

config.silent = true;             // If true pluribus will log nothing.
                                  //   Default: true

config.watch  = false;            // If true pluribus will watch for changes
                                  //   Default: false

config.workers = 2;               // How many workers to spawn.
                                  //   Default: number of CPUs

config.globs = [                  // Globs to watch.
    "/path/*",                    // Specify absolute paths, or pass each
    "/path/lib/*.js"              // element to path.resolve() (path = require("path")).
];                                // If path.resolve() is used, take care
                                  // to remove leading slashes from each relative path.
                                  // If watch is specified but globs is not,
                                  // it defaults to [ path.resolve("**/*.js"),
                                  // "!" + path.resolve(".", "node_modules", "**/*") ]

config.privs = {};                // Affects the privileges of workers.
config.privs.user  = "userName";  // The username to run workers as.
config.privs.group = "groupName"; // The group to run workers as.
                                  //    Default: nobody:nogroup

config.waitTimeout = 30000;       // The time (in ms) to wait for workers to drop
                                  // out before being forced to.
                                  //    Default: 30000 (30s)
1.3.0

7 years ago

1.2.0

9 years ago

1.1.1-beta

9 years ago

1.1.0-beta

9 years ago

1.0.1-beta

9 years ago

1.0.0-beta

10 years ago

0.1.0

10 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

12 years ago

0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago