Node.js rc.local脚本手动运行,但启动时失败…给出了什么?

Node.js rc.local脚本手动运行,但启动时失败…给出了什么?,node.js,startup,Node.js,Startup,我可以手动运行我的/etc/rc.local文件,它在启动时运行(将字符串回送到文件),但forever(npm包)由于某种原因失败。如果有帮助的话,我正在EC2实例上运行AmazonLinuxAMI 我在哪里可以了解它为什么失败,或者你能告诉我我做错了什么吗 #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization st

我可以手动运行我的/etc/rc.local文件,它在启动时运行(将字符串回送到文件),但forever(npm包)由于某种原因失败。如果有帮助的话,我正在EC2实例上运行AmazonLinuxAMI

我在哪里可以了解它为什么失败,或者你能告诉我我做错了什么吗

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

echo "rc.local is running..." > /tmp/rc.local-output

touch /var/lock/subsys/local

exec /usr/local/bin/forever start -c /usr/local/bin/node /var/www/node/myapp/app.js &
exec /usr/local/bin/forever start -c /usr/local/bin/node /var/www/node/myapp/tools/push/push_service.js &
好的,情况似乎有所好转,我将rc.local文件更新为:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

exec 2> /tmp/rc.local.log      # send stderr from rc.local to a log file
exec 1>&2                      # send stdout to the same log file
set -x                         # tell sh to display commands before execution

echo "rc.local is running..." >> /tmp/rc.local-output

touch /var/lock/subsys/local

/usr/local/bin/forever start /var/www/node/myapp/app.js &
/usr/local/bin/forever start /var/www/node/myapp/tools/push/push_service.js &
和/tmp/rc.local.log告诉我:


/usr/bin/env:node:没有这样的文件或目录

我想您仍然设置了执行位

ls -l /etc/rc.local

-rwxr-xr-x 1 root root 306 Dec 26  2010 /etc/rc.local
此外,脚本或工具
/usr/local/bin/forever
也必须是可执行的(“x”位设置适当),但您在手动测试时会检测到


我能想象这在启动时不起作用的唯一原因是它需要的东西到那时还没有准备好,因此永久工具的启动失败了。永远是剧本吗?如果是这样的话,也许你可以告诉我们里面有什么?

你可以通过在/etc/rc.local中设置来解决这个问题 su-c'/usr/local/node/bin/pm2 start/root/blog/hexo start.sh'--登录根

因为“use--login”可以找到节点环境。
--登录意味着
提供一个类似于用户直接登录时所期望的环境

永远是一个nodejs模块。它是在全球范围内安装的。是否有rc.local的日志可以指示失败的地方?在大多数情况下,初始化时的输出结果都是
/var/log/syslog
,除了内核引导过程被放入
/var/log/boot.log
。我根据这个问题/答案为节点添加了一个符号链接,看起来现在一切都正常了:D