A process management tool. Events, status, cluster, and automatic restarts.
npm install revive --save
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();
name: String
Defaults tonull
the name of the process.arg: Array, String
Defaults tonull
arguments or node script.cwd: String
Defaults toprocess.cwd()
the current working directory.cmd: String
Defaults toprocess.execPath
the systems absolute executable/node path.cluster: Boolean
Defaults tofalse
.instances: Number
Defaults toos.cpus().length
if cluster is set totrue
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 to1000
in milliseconds to sleep between start after a crash.crashTime: Number
Defaults to60000
ms. The time until themaxCrashCount
resets. So if1000
crashes happen in60
s then the process will exit.maxCrashCount: Number
Defaults to1000
crashes. A crash is triggered and the process exited atnth + 1
.env: {}
Environment variables for the process.data: {}
A custom object for you.
All methods execept toJson are async.
monitor.start()
Starts the monitormonitor.stop()
Stops the monitor (kills the process if its running withSIGKILL
).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.
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 aSIGTERM
signal. If the process does not terminate after ten seconds then the process is sent aSIGKILL
signal.monitor.on('restart', callback)
Same as stopping then starting or vice versa.monitor.on('stdout', callback)
Emits an stdout. Only available if noOptions.stdout
ispipe
.Stdout
Parameter the stdout message.
monitor.on('stderr', callback)
Emits an stderr. Only available if noOptions.stderr
ispipe
.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 codeSignal
The string signal
monitor.on('reload', callback)
Zero downtime restart ifcluster
is set totrue
andinstances
is greater than one.monitor.on('sleep', callback)
Triggered when process crashes and enters sleep.monitor.on('crash', callback)
Triggered when the process crashes.
Immediate start
then stop
execution does not send the signals. This could be a problem with node.js.
Why You Should Choose MPL-2.0 This project is licensed under the MPL-2.0 License