-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/pm2-integration' into dev
- Loading branch information
Showing
4 changed files
with
44 additions
and
1 deletion.
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: npm start | ||
web: npm run pm2 |
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
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,40 @@ | ||
// ref: <http://pm2.keymetrics.io/docs/usage/use-pm2-with-cloud-providers/> | ||
var pm2 = require('pm2'); | ||
|
||
var instances = process.env.WEB_CONCURRENCY || -1; // Set by Heroku or -1 to scale to max cpu core -1 | ||
var maxMemory = process.env.WEB_MEMORY || 512; // " " " | ||
|
||
pm2.connect(function() { | ||
pm2.start({ | ||
script: './build/server/server.js', | ||
name: 'production-app', // ----> THESE ATTRIBUTES ARE OPTIONAL: | ||
exec_mode: 'cluster', // ----> https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#schema | ||
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', | ||
AWESOME_SERVICE_API_TOKEN: 'xxx', | ||
}, | ||
}, function(err) { | ||
if (err) { | ||
return console.error( | ||
'Error while launching applications', | ||
err.stack || err | ||
); | ||
} | ||
console.log('PM2 and application has been succesfully 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); | ||
}); | ||
}); | ||
}); | ||
}); |