【问题标题】:rc.local script runs manually but fails on startup...what gives?rc.local 脚本手动运行但在启动时失败...什么给出?
【发布时间】:2014-08-05 02:42:50
【问题描述】:

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

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

#!/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.js startup


【解决方案1】:

我想你仍然设置了执行位?

ls -l /etc/rc.local

-rwxr-xr-x 1 root root 306 Dec 26  2010 /etc/rc.local

此外,脚本或工具 /usr/local/bin/forever 也必须是可执行的('x' 位设置得当),但您在手动测试时会检测到。

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

【讨论】:

  • forever 是一个 nodejs 模块。它已在全球范围内安装。是否有 rc.local 的日志可能指示失败的原因?
  • 在大多数情况下,初始化时的输出以/var/log/syslog 结束,除了放在/var/log/boot.log 中的内核启动过程。
【解决方案2】:

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

因为 'use --login' 可以找到节点环境。 --login 表示Provide an environment similar to what the user would expect had the user logged in directly

【讨论】:

    猜你喜欢
    • 2011-12-08
    • 2013-01-14
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 2022-09-30
    相关资源
    最近更新 更多