pm2-interface permits you to interact with PM2 the process manager for NodeJS.
You can control all exposed methods by the pm2 deamon God and also receive real time notifications for example for a process who got an unexpectedException, who's starting/stopping.
ipm2.rpc.prepare(json, fn)
send a JSON configuration to start app(s)ipm2.rpc.getMonitorData({}, fn)
receive all related informations about supervised process (cpu/ram/pid...)ipm2.rpc.startProcessId(integer, fn)
start a process by id (pm_id) who his state is stoppedipm2.rpc.stopProcessId(integer, fn)
stop a process by id (pm_id)ipm2.rpc.stopAll({}, fn)
stop all processipm2.rpc.reload(data, fn)
reload all apps (only for networked apps)ipm2.rpc.killMe(data, fn)
kill pm2 daemonipm2.rpc.findByScript(string, fn)
send you back the informations about a specific processipm2.rpc.restartProcessId(integer, fn)
restart a process by id (pm_id)ipm2.rpc.restartProcessName(string, fn)
restart all processes who have the given nameipm2.rpc.deleteProcess(string, fn)
stop and delete all processes from the pm2 databaseipm2.rpc.deleteAll(data, fn)
stop and delete all processes
process:online
when a process is started/restartedprocess:exit
when a process is exitedprocess:exception
When a process has received an uncaughtException
Advanced feature : You can use process.emit({ type : 'my:message', data : {}})
in your Node apps. When you emit a message, they will be redirected to pm2 ans send back to the pm2-interface bus.
var ipm2 = require('pm2-interface')();
ipm2.on('ready', function() {
console.log('Connected to pm2');
ipm2.bus.on('*', function(event, data){
console.log(event, data.pm2_env.name);
});
setTimeout(function() {
ipm2.rpc.restartProcessId(0, function(err, dt) {
console.log(dt);
});
}, 2000);
ipm2.rpc.getMonitorData({}, function(err, dt) {
console.log(dt);
});
});
- Catching exceptions and fowarding them by mail
- A web interface to control PM2