[英]pm2 - Startup script for non-root user permission denied
我剛剛安裝了 pm2(在 Debian 9 上),我需要運行少數用戶的 NodeJS 服務器。 每個用戶都有自己的 NodeJS 服務器,我需要在它們下運行。 不在根下。
例如我有用戶“user1”:
pm2 startup
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 身份執行!!
每次重啟我都需要“授予”權限。
如何解決這個問題?
我不確定以下方法是否有任何風險,但它確實解決了我面臨的相同問題。
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
我發現自己為什么它不起作用。 我的用戶名帶有 dot (domain.com) 並且 systemd 無法將其識別為有效的用戶名...因為該服務是在 root 下啟動的。
快速修復是在 systemd 中找到自動生成的服務,並用id -u <user>
找到的用戶 ID 替換用戶名
您可能使用 root 啟動了 pm2 任務。 因此,請通過以下方式檢查您正在使用的系統進程:
sudo systemctl -a
如果您找到一個單位名稱 pm2-root,那就是您需要刪除的單位。 運行命令sudo systemctl stop
pm2-root 和sudo systemctl disable pm2-root
。 然后使用您的用戶名啟動該過程。
確保您使用pm2-sammy和sammy作為您的用戶名。
嘗試使用sudo pm2 <command>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.