blog
blog copied to clipboard
Installing pm2 on IBM i
This is a guide to installing PM2 on IBM i. I recommend either using Node.js 8 or Node.js v10 with PM2, which are both available via yum.
Step 1
Check you have Node.js installed. If running node -v
doesn't show you the version and instead errors that it can't find the correct version of node, you may need to add the package installation directory to your $PATH
: PATH=/QOpenSys/pkgs/bin:$PATH
. If you are running Node.js 6, I suggest you install yum to update.
Step 2
Install pm2 with npm.
-bash-4.3$ npm i -g pm2
/QOpenSys/pkgs/lib/nodejs10/bin/pm2 -> /QOpenSys/pkgs/lib/nodejs10/lib/node_modules/pm2/bin/pm2
/QOpenSys/pkgs/lib/nodejs10/bin/pm2-docker -> /QOpenSys/pkgs/lib/nodejs10/lib/node_modules/pm2/bin/pm2-docker
/QOpenSys/pkgs/lib/nodejs10/bin/pm2-dev -> /QOpenSys/pkgs/lib/nodejs10/lib/node_modules/pm2/bin/pm2-dev
/QOpenSys/pkgs/lib/nodejs10/bin/pm2-runtime -> /QOpenSys/pkgs/lib/nodejs10/lib/node_modules/pm2/bin/pm2-runtime
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]:
wanted {"os":"darwin","arch":"any"} (current: {"os":"aix","arch":"ppc64"})
+ [email protected]
added 261 packages from 225 contributors in 24.028s
Step 3
Test the pm2
command. If you execute pm2
and get command not found
, then you need to add the Node.js bin
library to your path. Note that the Node.js bin
directory is different for different Node.js versions.
-bash-4.3$ pm2
-bash: pm2: command not found
-bash-4.3$ PATH=/QOpenSys/pkgs/lib/nodejs10/bin:$PATH
-bash-4.3$ pm2
usage: pm2 [options]
pm2 -h, --help all available commands and options
pm2 examples display pm2 usage examples
pm2 -h help on a specific command
Access pm2 files in ~/.pm2
That's it
You now have PM2. You may want to set up a .profile
to add the Node.js bin
directory to your $PATH
(like we did above) automatically.
PATH=/QOpenSys/pkgs/bin:/QOpenSys/pkgs/lib/nodejs10/bin:$PATH
Hi Liam, Thank you for this article, the installation of pm2 works fine ! Idem for pm2 start and stop commands. I'm working in Node.js on IBM i project and I want to use pm2 for my node.js script in production.
But I have a problem with displaying pm2 list command (and other commands). I guess it's due to special characters. Do you have already encountered the same problem ? Do you have any idea to solve this issue ?
I have that same issue as GautierFR. I also have another question.
I have a Node web server script stored in my home directory /home/mydir and was starting the script from there. I have a .profile setup so that when I would SSH in using Putty and do PM2 STATUS, I would see the job running.
I've since moved the script to /QOpenSys/etc thinking it would be more generic and not show up as me. Another user started the script, my PM2 web server is running, it's working, but I can't find it! It's also created 1400 little log spool files!
Help!
To complete my precedent comment, with ssh putty session, the table is displayed correctly.
But a special character continues to display poorly (4th column of the table for example).
GautierFR - I have an unrelated question about your script placement. When you put your scripts in the IFS like that, how do you reference or require to NPM packages? Are they all installed in /www/NodeJS10?
I'm trying to place stuff so that it's more global. So far a lot of my scripts are in my /home/usrprf directory.
betsonserviceportal - In general, I prefer to work with local dependencies on my different projects rather than global ones. I consider that it is more easily portable. As for the location of my example (/www/nodeJs10), it was just for my tests, on a partition without production, where I'm the only developer. With a development team, I think it might be a good idea to work in /home/usrprf for each developer, with local dependencies, then deployments outside /home for the recipe, pre-prod , production etc ...
Wondering two things. Can you determine from your RPG if your PM2 server is running? I can ping an IP address, but not a port. I may be able to use something of Scott's to check the IP and port. Just wondering.
Also, I have a script which starts my PM2 server, but when I go to end it, the same commands that end the server when logged in via Putty, leave one Node job running out there. I typically have two Node jobs created by my start-up script. If I go into WRKUSRJOB and end one, they both usually end. Just not when I do it via a script.
Thanks. Mike
Hi Liam,
Thanks for these instructions! I've gotten this to work, but I am struggling to get the pm2 daemon to restart after a system IPL. AIX is not a supported system for PM2's startup script generator (https://pm2.keymetrics.io/docs/usage/startup/). I'm exploring options for this and I'm wondering if you have implemented a startup script for pm2 already. Do you have any tips for this?
I don't know if this is what you were looking for, but here are our start and end scripts called by a CL which is run from the job scheduler.
Start: #!/QOpenSys/usr/bin/sh cd /QOpenSys/etc; PATH=/QOpenSys/pkgs/lib/nodejs10/bin:/QOpenSys/pkgs:/QOpenSys/pkgs/bin:$PATH; export PATH; pm2 kill; pm2 start /QOpenSys/pkgs/lib/nodejs10/lib/node_modules/paymentus.js > /QOpenSys/etc/paymentusLog.txt;
End: #!/QOpenSys/usr/bin/sh cd /QOpenSys/etc; PATH=/QOpenSys/pkgs/lib/nodejs10/bin:/QOpenSys/pkgs:/QOpenSys/pkgs/bin:$PATH; export PATH; pm2 kill; ps -ef | grep pm2 | awk '{ print $2 }' | xargs kill -9;
Thanks for the details. I got the pm2 working on AIX and was able to start my node application using pm2. But I am stuck on how I can restart pm2 on AIX restart. As mentioned in comments above, the startup script is not supported for AIX. I did include starting my application using pm2 in /etc/inittab. That starts the node application after AIX restarts but the process does not remain in pm2 list later. Any help on how to auto restart my node application using pm2 after a AIX restart?