Created
November 30, 2015 21:52
-
-
Save brunoguerra/720a83498f74e11712ea to your computer and use it in GitHub Desktop.
PM2 Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pmx = require('pmx').init({ | |
http : true, | |
network : true, | |
ports : true | |
}); | |
var pm2 = require('pm2'); | |
var path = require('path'); | |
var MACHINE_NAME = process.env.APP_NAME; | |
var PRIVATE_KEY = process.env.KEYMETRICS_PVT_KEY; // Keymetrics Private key | |
var PUBLIC_KEY = process.env.KEYMETRICS_PUB_KEY; // Keymetrics Public key | |
if (PRIVATE_KEY && PUBLIC_KEY) { | |
pm2.connect(function() { | |
pm2.start({ | |
script : path.join(__dirname, 'index.js'), | |
name : process.env.APP_NAME, | |
}, function() { | |
pm2.interact(PRIVATE_KEY, PUBLIC_KEY, MACHINE_NAME, function() { | |
// Display logs in standard output | |
launchBus(); | |
}); | |
}); | |
}); | |
} else { | |
require('./index'); | |
} | |
function launchBus() { | |
pm2.launchBus(function(err, bus) { | |
console.log('[PM2] Log streaming started'); | |
bus.on('log:out', function(packet) { | |
console.log('[App:%s] %s', packet.process.name, packet.data); | |
}); | |
bus.on('log:err', function(packet) { | |
console.error('[App:%s][Err] %s', packet.process.name, packet.data); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment