Baterka
Baterka

Reputation: 722

pm2 - Startup script for non-root user permission denied

I just installed pm2 (on Debian 9) and I need to run NodeJS server of few users. Every user have own NodeJS server what I need to run under them. Not under root.

For example I have user "user1":

pm2 still works on user1, but after restart I cannot control pm2 and Iam getting this error: [PM2][ERROR] Permission denied, to give access to current user: $ sudo chown user1:user1 /home/user1/.pm2/rpc.sock /home/user1/.pm2/pub.sock

If I execute this command on root, I can then again control pm2 on user1, but all NodeJS servers are executed as root!!

I need to 'grant' permissions every restart..

How to fix this?

Upvotes: 4

Views: 23109

Answers (4)

Satys
Satys

Reputation: 2425

I'm not sure if there are any risk with the following method, but it did solve same issue I was facing.

  1. open new terminal (fresh, without sudo permission)
  2. sudo chmod -R 777 /home/user1/.pm2 (gives permission to the .pm2 folder)
  3. pm2 start index.js (Note that there is no sudo here)
  4. pm2 save
  5. pm2 startup
  6. Restart your computer and check pm2 monit
  7. It should list your index process now. If not, try from 1-5, 8, and then 6.
  8. paste the command listed in step 5

Upvotes: 10

Apurv Gupta
Apurv Gupta

Reputation: 1

Try using sudo pm2 <command>

Upvotes: -1

William Gu
William Gu

Reputation: 21

You probably started the pm2 tasks using root. So check the system processes that you are using by:

sudo systemctl -a

If you find a unit name pm2-root, that is the one that you need to remove. Run the command sudo systemctl stop pm2-root and sudo systemctl disable pm2-root. Then use your user name to start the process.

Make sure you are using pm2-sammy with sammy as your user name.

Upvotes: 2

user7757483
user7757483

Reputation:

I found myself why it not work. My user names are with dot (domain.com) and systemd not recognised this as valid user name... Because that service started under root.

Quick fix is to find auto-generated service in systemd and replace user name with user id found by id -u <user>

Upvotes: 2

Related Questions