Snippets

litmis pm2 for Node.js on IBM i

Created by Aaron Bartell

| | | - | - | - | - IBM i Hosting | Cybersource Toolkit for i | RPG-XML Suite | Payment Terminal Toolkit for i | UPS Toolkit for i

pm2 for Node.js on IBM i

PM2 is a General Purpose Process Manager and a Production Runtime for Node.js apps with a built-in Load Balancer. This tutorial will cover installation on an IBM i v7.3 machine running Node.js v8 in a chroot container.

First, install pm2.

$ npm install pm2
npm WARN saveError ENOENT: no such file or directory, open '/home/AARON/pm2/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/AARON/pm2/package.json'
npm WARN pm2 No description
npm WARN pm2 No repository field.
npm WARN pm2 No README data
npm WARN pm2 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"aix","arch":"ppc64"})

+ pm2@2.10.1
added 370 packages in 246.03s

A simple app to test with.

app.js

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8001);

Here's the successful start. I didn't install it globally so I needed to fully qualify the local path to the pm2 runtime.

$ node_modules/pm2/bin/pm2 start app.js

                        -------------

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
 _\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
  _\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
   _\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
    _\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
     _\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
      _\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
       _\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
        _\///______________\///______________\///__\///////////////__


                          Community Edition

            Production Process Manager for Node.js applications
                     with a built-in Load Balancer.


                Start and Daemonize any application:
                $ pm2 start app.js

                Load Balance 4 instances of api.js:
                $ pm2 start api.js -i 4

                Monitor in production:
                $ pm2 monitor

                Make pm2 auto-boot at server restart:
                $ pm2 startup

                To go further checkout:
                http://pm2.io/


                        -------------

[PM2] Spawning PM2 daemon with pm2_home=/home/AARON/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /home/AARON/pm2/app.js in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬──────┬────────┬────────┬─────────┬────────┬─────┬────────┬───────┬──────────┐
 App name  id  mode  pid     status  restart  uptime  cpu  mem     user   watching 
├──────────┼────┼──────┼────────┼────────┼─────────┼────────┼─────┼────────┼───────┼──────────┤
 app       0   fork  340977  online  0        2s      0%   0 B     aaron  disabled 
└──────────┴────┴──────┴────────┴────────┴─────────┴────────┴─────┴────────┴───────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

And stopping it.

$ node_modules/pm2/bin/pm2 stop all
[PM2] Applying action stopProcessId on app [all](ids: 0)
[PM2] [app](0) 
┌──────────┬────┬──────┬─────┬─────────┬─────────┬────────┬─────┬────────┬───────┬──────────┐
 App name  id  mode  pid  status   restart  uptime  cpu  mem     user   watching 
├──────────┼────┼──────┼─────┼─────────┼─────────┼────────┼─────┼────────┼───────┼──────────┤
 app       0   fork  0    stopped  0        0       0%   0 B     aaron  disabled 
└──────────┴────┴──────┴─────┴─────────┴─────────┴────────┴─────┴────────┴───────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.