Start app as root with pm2

前端 未结 7 1836
遥遥无期
遥遥无期 2021-01-31 17:29

I have a daemon that must be run as root on startup.

I use pm2 to start other apps but can not figure out if it can start an app as root. Can it be done?

If not,

7条回答
  •  面向向阳花
    2021-01-31 18:06

    Wasted about an hour

    On AWS EC2 machine, one system was in inconsistent state due to earlier installations, that forced sudo elevations in the application for all commands to OS, like sh, etc.

    pm2 was running as root:

    ps aux | grep pm2
    # root ... PM2 v4.1.2: God Daemon (/root/.pm2)
    

    Now pm2 is running as ubuntu:

    ps aux | grep pm2
    # ubuntu  ...  PM2 v4.1.2: God Daemon (/home/ubuntu/.pm2)
    

    Below commands worked:

    sudo pm2 kill
    sudo npm remove pm2 -g
    
    sudo npm i -g pm2@latest
    sudo pm2 update
    sudo chown -R ubuntu:ubuntu /home/ubuntu/.pm2
    

    Hope that helps

提交回复
热议问题