respawn-group
Manage a group of respawn monitors
npm install respawn-group
Usage
var regroup = require('respawn-group');
var group = regroup();
group.add('test', ['node', 'server.js']);
group.start('test');
API
regroup(defaults) -> group
Instantiate a new respawn group. Allopts
will inherit fromdefaults
group.add(id, command, opts) -> mon
Add a new respawn monitor. See respawn for more information. If you add a new monitor with the same id as an old one it will be used when the old monitor stops.group.remove(id, cb)
Remove a monitorgroup.start(id) -> mon
Start a monitorgroup.stop(id, cb)
Stop a monitorgroup.restart(id) -> mon
Gracefully restart a monitorgroup.get(id) -> mon
Get a monitorgroup.has(id) -> bool
True is group has monitorgroup.list() -> array
List all monitorsgroup.shutdown(cb)
Stop all services and ignore all following starts
Events
group.on('start', mon)
Monitor has started.mon.id
contains the id of the monitorgroup.on('stop', mon)
Monitor is fully stoppedgroup.on('crash', mon)
Monitor has crashedgroup.on('restart', mon)
Monitor is being restartedgroup.on('sleep', mon)
Monitor is sleepinggroup.on('spawn', mon, process)
Monitor has spawned a child processgroup.on('exit', mon, code, signal)
Monitors child process has exitedgroup.on('stdout', mon, data)
child process stdout has emitted datagroup.on('stderr', mon, data)
child process stderr has emitted datagroup.on('warn', mon, err)
Monitor has a warninggroup.on('finalize', mon)
A monitor is fully stopped and being garbage collected. Happens if you call remove or updates a monitor
Updating existing monitors
To update an existing monitor simply add it again with the same id
group.add('test', ['node', 'server.js']);
// ... wait a bit ...
// now lets update test
group.add('test', ['node', 'server2.js']);
group.restart('test'); // you need to restart test for the new monitor to take over
// this will trigger a 'finalize' event for the old monitor
License
MIT