-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d6ec5b
commit d77eaab
Showing
3 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web: node app.js | ||
web: node pm2-main.js |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var pm2 = require('pm2'); | ||
|
||
var instances = process.env.WEB_CONCURRENCY || 1; // Set by Heroku or 1 (set -1 to scale to max cpu core - 1) | ||
var maxMemory = process.env.WEB_MEMORY || 512; // 512 is the maximum free Dyno memory on Heroku | ||
|
||
pm2.connect(function() { | ||
pm2.start({ | ||
script : 'app.js', | ||
name : 'msr', // ----> THESE ATTRIBUTES ARE OPTIONAL: | ||
exec_mode : 'cluster', // set to 'cluster' for cluster execution | ||
instances : instances, | ||
max_memory_restart : maxMemory + 'M', // Auto restart if process taking more than XXmo | ||
env: { // If needed declare some environment variables | ||
"NODE_ENV": "production" | ||
} | ||
}, function(err) { | ||
if (err) return console.error('Error while launching applications', err.stack || err); | ||
console.log('PM2 and application has been successfully started'); | ||
|
||
// Display logs in standard output | ||
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); | ||
}); | ||
}); | ||
|
||
}); | ||
}); | ||
|