如何与非root用户一起使用pm2启动? [英] How do you use pm2 startup with a non-root user?

查看:1037
本文介绍了如何与非root用户一起使用pm2启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此处的文档: http://pm2. keymetrics.io/docs/usage/startup/#startup-systems-support

您可以使用命令pm2 startup ubuntu -u nodeapps在服务器启动时恢复所有已保存的pm2作业.

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

我以nodeapps用户身份运行了此命令.然后,我得到了一个sudo su命令来运行.我注销了nodeapps,使用sudo su以root用户身份登录系统,然后运行以下命令:

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"

在服务器重新启动时,进程未重新启动.我在堆栈溢出中发现了以下问题: Ubuntu 14.04-pm2启动不重新启动后开始.

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

在脚本/etc/init.d/pm2-init.sh中,我找到了该问题建议解决的那一行:

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.

然后我发现了以下问题: pm2启动无法在Ubuntu上启动

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

我知道Ubuntu上的节点"实际上是"nodejs".这可能是原因吗?

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

如果是,我该怎么办才能使启动命令查找nodejs而不是node.

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

或者,这可能是$ PATH问题吗?如果是这样,我如何才能将正确的路径添加到根目录(至少我认为应该将其添加到根目录)

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)

推荐答案

(代表OP发布).

实际上,这就是问题所在.通过创建符号链接(以root用户身份)进行了修复:

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

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

这篇关于如何与非root用户一起使用pm2启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆