How do you use pm2 startup with a non-root user?

不想你离开。 提交于 2019-12-21 17:46:12

问题


According to the documentation here: http://pm2.keymetrics.io/docs/usage/startup/#startup-systems-support

You can use the command pm2 startup ubuntu -u nodeapps to resurrect all saved pm2 jobs on server startup.

I ran this command as the nodeapps user. Then I was given a sudo su command to run. I logged out of nodeapps, used sudo su to log into the system as root, and ran the command:

sudo su -c "env PATH=$PATH:/usr/bin pm2 startup ubuntu -u nodapps --hp /home/nodeapps"

The processes did not restart on server restart. I found this question on Stack Overflow: Ubuntu 14.04 - pm2 startup not starting after reboot.

In the script /etc/init.d/pm2-init.sh I found the line that question recommended addressing:

export PATH=/usr/bin:$PATH
export PM2_HOME="/home/nodeapps/.pm2"

But it looks correct to me so I didn't change anything.

I then found this question: pm2 Startup not starting up on Ubuntu

and in my boot logs I find the following line:

Starting pm2
/usr/bin/env: node: No such file or directory

I know that 'node' on Ubuntu is actually 'nodejs'. Could this be the reason?

If it is, what can I do to make the startup command look for nodejs instead of node.

Alternatively, could this be a $PATH problem? If it is, how can I add the correct path to root (at least I think it should be added to root)


回答1:


(Posted on behalf of the OP).

In fact that was the problem. Fixed via creating a symlink (as root):

ln -s /usr/bin/nodejs /usr/sbin/node


来源:https://stackoverflow.com/questions/37587388/how-do-you-use-pm2-startup-with-a-non-root-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!