简体   繁体   English

为什么Forever for Node.JS不能在rc.local中工作?

[英]Why does Forever for Node.JS not work in rc.local?

I am deploying a node.js app to a Ubuntu server on EC2, and I am using Forever to keep it running ... forever. 我正在将一个node.js应用程序部署到EC2上的Ubuntu服务器上,并且我正在使用Forever使其永远运行。

The problem is, if I type in following in a console: 问题是,如果我在控制台中输入以下内容:

forever start ~/path/myapp.js

It works just fine. 它工作正常。 But I want the app automatically starts when on startup, so I appended the line to /etc/rc.local, and it stopped working. 但是我希望应用程序在启动时自动启动,因此我将该行附加到了/etc/rc.local,并且它停止了工作。 Everything else in rc.local still works. rc.local中的所有其他内容仍然有效。

I am not familiar with Linux so my best guess is some important component hasn't initialized when running rc.local. 我对Linux不熟悉,所以我最好的猜测是运行rc.local时某些重要组件尚未初始化。 Is there somewhere else I can append the line? 我可以在其他地方附加行吗?

Thanks, 谢谢,

I'm pretty sure it has something to do with the user who is actually running the commands in /etc/rc.local . 我很确定这与实际上在/etc/rc.local运行命令的用户有关。 As ~ specifies the user's home directory, this may be non-existent, different than expected, or just not loaded when the script runs. 由于~指定用户的主目录,因此该目录可能不存在,与预期的不同,或者仅在脚本运行时未加载。 I would suggest trying the following: 我建议尝试以下方法:

forever start /path/to/home/path/myapp.js

This is a very late reply, but I just ran into this. 这是一个很晚的答复,但是我遇到了这个问题。 For me, using forever list says that nothing is running, but doing sudo forever list will show that the server is in fact running. 对我而言,使用forever list表示没有任何运行,但是执行sudo forever list将显示服务器实际上正在运行。

This is because rc.local is run as root, so your forever command is run as root, and only root can see it in the list. 这是因为rc.local是作为root运行的,因此您的永远命令都是作为root运行的,只有root可以在列表中看到它。

I don't know the best practices, but I got around it by calling my forever start script from rc.local like this, where "pi" is the user I want to launch the forever process: 我不知道最佳实践,但是我通过从rc.local调用永久启动脚本来解决此问题,其中“ pi”是我要启动永久进程的用户:

su pi -c './start'

If it helps, this is my abridged ./start script, yours may differ, or you can possibly put its contents directly in rc.local: 如果有帮助,这是我的简化的./start脚本,您的脚本可能有所不同,或者您可以将其内容直接放在rc.local中:

#!/bin/sh forever start --append -l forever.log -o server.log -e error.log server.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM