Skip to content

Instantly share code, notes, and snippets.

@jimmed
Forked from Unitech/bootstrap
Last active August 29, 2015 14:26
Show Gist options
  • Save jimmed/f66c0b0fc7e2cb79ce8c to your computer and use it in GitHub Desktop.
Save jimmed/f66c0b0fc7e2cb79ce8c to your computer and use it in GitHub Desktop.
PM2 / Keymetrics for Heroku/Rackspace/Joyent/Amazon Elasticbeanstalk/Azure...
// Make sure you added pm2 as a dependency in your package.json
// Then in your Procfile, do a simple `node bootstrap.js`
var pm2 = require('pm2');
var MACHINE_NAME = 'hk1';
var PRIVATE_KEY = 'z1ormi9vomgq66';
var PUBLIC_KEY = 'oa0m7nuhdfibi16';
var instances = process.env.WEB_CONCURRENCY || 1; // Set by Heroku
var maxMemory = process.env.WEB_MEMORY || 512; // " " "
pm2.connect(function() {
pm2.start({
script : 'app.js',
instances : instances, // Scale app based on Heroku's recommendations
max_memory_restart : maxMemory + 'M' // Auto restart if process taking more than 100mo
env: { // If needed declare some environment variables
"NODE_ENV": "production",
"AWESOME_SERVICE_API_TOKEN": "xxx"
},
post_update: ["npm install"] // Commands to execute once we do a pull from Keymetrics
}, function() {
pm2.interact(PRIVATE_KEY, PUBLIC_KEY, MACHINE_NAME, function() {});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment