pm2 - 非 root 用户权限的启动脚本被拒绝

Bat*_*rka 3 root node.js pm2

我刚刚安装了 pm2(在 Debian 9 上),我需要运行少数用户的 NodeJS 服务器。每个用户都有自己的 NodeJS 服务器,我需要在它们下运行。不在根下。

例如我有用户“user1”:

  • 我可以正常控制pm2
  • 用于启用启动脚本的 user1 上的此命令: pm2 startup
  • 然后我将输出的命令复制粘贴到 root 并执行...
  • 现在已创建给定用户的启动脚本

pm2 仍然适用于 user1,但重启后我无法控制 pm2 并且我收到此错误: [PM2][ERROR] Permission denied, to give access to current user: $ sudo chown user1:user1 /home/user1/.pm2/rpc.sock /home/user1/.pm2/pub.sock

如果我在 root 上执行这个命令,我可以再次控制 user1 上的 pm2,但是所有 NodeJS 服务器都以 root 身份执行!!

每次重启我都需要“授予”权限。

如何解决这个问题?

Sat*_*tys 7

我不确定以下方法是否有任何风险,但它确实解决了我面临的相同问题。

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
Run Code Online (Sandbox Code Playgroud)