Edgemicro + PM2: Starting edgemicro as a service

PM2 is a production process manager for node applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.

As we will see belowm Edge Microgateway, been a node app can benefit greatly from using this tool,

Find below the steps required to use PM2 with edgemicro:

  1. Start edgemicro using the following command:
    $ pm2 start edgemicro -- start -o <org> -e <env> -k <key> -s <secret>
  2. Check that edgemicro started properly having a look at the logs:
    $ pm2 logs edgemicro<br>
  3. You can also have more details of the process running (pid, uptime, cpu usage, memory usage,...) with this other command:
    $ pm2 list
  4. Get the automatically-configured startup script for your machine you need to typing this command:
    $ pm2 startup	

    It automaticallly detects the available init system, but you can specify it yourself to (eg: pm2 startup systemd). You can also use option -u to specify the user and --hp to specify the home directory.

  5. Once the scripts are generated run the following command to keep a list of the processes runing, so they will be started at boot time.
    $ pm2 save	
  6. If you want to actively monitor how edgemicro is performing you just nee to run:
    $ pm2 monit
  7. In case you would like to have a Keymetrics dashboard, you can just go ahead and sign in for an account there, create a bucket and run the following command with the provided keys:
    $ pm2 link <secret-key> <public-key>

Give it a try and let me know how it goes.

Comments
davissean
Staff

Very nice write up, thanks Miren.

It is also worth noting that Edge Cloud developers that want to debug NodeJS proxies locally can also use PM2 and follow similar steps... although nodemon may be simpler for this purpose.

Version history
Last update:
‎01-20-2017 07:29 AM
Updated by: