When I start my Nodejs app with pm2, other server users are not able to access the process.
Even if I start pm2 from a custom directory (not current user's ~/
, what pm2 is using by default):
HOME=/var/www pm2 start app.js
Directory is accessible by any user (comparing to ~/
, but there's still no way other server user is able to access the process.
When other server user does pm2 list
, it shows him 0 processes are running – but there are (started by another user). And when other user tries HOME=/var/www pm2 list
, CLI throws an error:
events.js:72 throw er; // Unhandled 'error' event ^ Error: connect EACCES at errnoException (net.js:905:11) at Object.afterConnect [as oncomplete] (net.js:896:19)
So I am wondering how to make sure users are able to access pm2 processes run by other server users? Or it shall be approached differently?
I am wondering why every server user is able to make git pull
to deploy latest source code from a Git repository, but can't restart pm2
process afterwards? Only the user that started pm2
process is able to restart it… Weird.
yes, you need to install it globally.
To get an overview of the processes currently managed by PM2, you can print out a comprehensive list using the command line utility. The output shows basic information about the running processes like app name and id, the mode ( fork or cluster ), status, uptime, memory footprint, etc.
PM2 is a Node. js process manager that comes with a built-in load balancer. It helps facilitate production deployments and enables you to keep running applications alive indefinitely (even when accidents occur).
Here's how we bypassed this.
Just create a group
Create a new group pm2
or whatever name works for you
$ groupadd pm2
Change the /var/www/
folder group owner to group pm2
$ chgrp -R pm2 /var/www
Add the other user, let's say bob, to pm2
$ usermod -aG pm2 bob
Now bob can run pm2 commands by changing $HOME to /var/www
$ env HOME=/var/www pm2 list
Or (better still) create an alias as @jcollum suggested
$ alias pm2='env HOME=/var/www pm2'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With