Code Monkey home page Code Monkey logo

revive's Introduction

Revive

A process management tool. Events, status, cluster, and automatic restarts.

Install

npm install revive --save

Example

const Revive = require('revive');

const options = {
	name: 'test',

	cmd: process.execPath,

	arg: ['app.js'],
	env: { PORT: 8000 },
	cwd: '/home/user/code/node/app/.',

	cluster: true,
	instances: 2,

	stdout: '/logs/stdout.log',
	stderr: '/logs/stderr.log',

	sleepTime: 1000,
	crashTime: 6 * 1000,
	maxCrashCount: 1000
};

const monitor = new Revive(options);

monitor.on('start', function () {
	console.log(monitor.toJSON());
});

monitor.start();

Options

  • name: String Defaults to null the name of the process.
  • arg: Array, String Defaults to null arguments or node script.
  • cwd: String Defaults to process.cwd() the current working directory.
  • cmd: String Defaults to process.execPath the systems absolute executable/node path.
  • cluster: Boolean Defaults to false.
  • instances: Number Defaults to os.cpus().length if cluster is set to true
  • stdout: String Defaults to 'pipe' otherwise a file path. If a path is provided than this event will not fire.
  • stderr: String Defaults to 'pipe' otherwise a file path. If a path is provided than this event will not fire.
  • sleepTime: Array, Number Defaults to 1000 in milliseconds to sleep between start after a crash.
  • crashTime: Number Defaults to 60000ms. The time until the maxCrashCount resets. So if 1000 crashes happen in 60s then the process will exit.
  • maxCrashCount: Number Defaults to 1000 crashes. A crash is triggered and the process exited at nth + 1.
  • env: {} Environment variables for the process.
  • data: {} A custom object for you.

API

All methods execept toJson are async.

  • monitor.start() Starts the monitor
  • monitor.stop() Stops the monitor (kills the process if its running with SIGKILL).
  • monitor.restart() Restarts the monitor by stopping then starting (process must be started).
  • monitor.toJSON() Creates a stringyifiable object. The object returns stats and data about the process.

Cluster Events

  • monitor.on('status', callback)
  • monitor.on('start', callback) Starts the process. Warning async so process may not be available immediately.
  • monitor.on('stop', callback) The process and it's tree is sent a SIGTERM signal. If the process does not terminate after ten seconds then the process is sent a SIGKILL signal.
  • monitor.on('restart', callback) Same as stopping then starting or vice versa.
  • monitor.on('stdout', callback) Emits an stdout. Only available if no Options.stdout is pipe.
    • Stdout Parameter the stdout message.
  • monitor.on('stderr', callback) Emits an stderr. Only available if no Options.stderr is pipe.
    • Stderr Parameter the stderr message.
  • monitor.on('error', callback) Emits when the process could not spawn, kill, or a message failed.
    • Error Parameter the error message.
  • monitor.on('exit', callback) The process has exited.
    • Code The numeric exit code
    • Signal The string signal

Instance Events

  • monitor.on('reload', callback) Zero downtime restart if cluster is set to true and instances is greater than one.
  • monitor.on('sleep', callback) Triggered when process crashes and enters sleep.
  • monitor.on('crash', callback) Triggered when the process crashes.

Issues

Immediate start then stop execution does not send the signals. This could be a problem with node.js.

Authors

AlexanderElias

License

Why You Should Choose MPL-2.0 This project is licensed under the MPL-2.0 License

revive's People

Contributors

xeaone avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

revive's Issues

I copied and pasted the example code from readme and it gives me an error when I run the .js file

C:\Users\BOINC\Desktop\revivetest>node revive.js
{ pid: undefined,
  name: 'test',
  status: 'started',
  exits: 0,
  stops: 0,
  starts: 1,
  errors: 0,
  sleeps: 0,
  crashes: 0,
  restarts: 0,
  exited: null,
  created: 1466055278899,
  stopped: null,
  started: 1466055278930,
  errored: null,
  sleeped: null,
  crashed: null,
  restarted: null,
  sleepTime: 1000,
  paddingTime: 5000,
  maxSleepCount: 1000,
  cwd: '/home/user/code/node/app/.',
  arg: [ 'app.js' ],
  stdout: '/logs/stdout.log',
  stderr: '/logs/stderr.log',
  env: { PORT: 4444 },
  data: {} }
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: spawn C:\Program Files\nodejs\node.exe ENOENT
    at exports._errnoException (util.js:870:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)
    at Function.Module.runMain (module.js:443:11)
    at startup (node.js:139:18)
    at node.js:968:3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.