Mantra how-to guide
Use PM2 as daemon process manager to run Mantra projects
PM2 is an amazing tool to use in your deployments with a number of great features
Mantra allows you to build scalable projects but how they are deployed depends on their application lifecycle management, the testing methodology and so on.
As any other Node.js application, you need to run it as a daemon in a production environment.
There are a number of options to do this, but we like a lot PM2 tool for this and we use it in our deployments since long time ago.
Just install it with:
$ npm install pm2 -g
With PM2, you just make your application as a daemon running a simple command in the line interface.
To run a Mantra project which has an application named as "coreapp", for instance, just type:
$ pm2 start mantrad --name coreapp -- startapp coreapp
With '--', you indicate the paramenters to include in the command you are launching.
By doing so, your "coreapp" application will be running as a daemon in the machine and you can log out safely with your app running.
Usually, a Mantra project is composed as a number of differents applications that works together, so, to launch them at a the same time in a single machine, you can writ an script similar to this (as an example):
pm2 start mantrad --name myproject.coreapp -- startapp coreapp
pm2 start mantrad --name myproject.adminapp -- startapp adminapp
pm2 start mantrad --name myproject.tasksmanager -- startapp taskerapp
pm2 start mantrad --name myproject.publicapi -- startapp publicapiapp
PM2 has lots os features to explore and use in the maintenance of your projects:
$ pm2 list
, will show all daemons up & running currently.
$ pm2 stopall
, will stop all daemons running.
$ pm2 monitor
, will open a simple user interface to get information profile of your applications.
Refer to PM2 documentation to learn many other options.