rc.local脚本手动运行但在启动时失败...是什么给出的?

时间:2014-08-05 02:42:51

标签: node.js startup

我可以手动运行我的/etc/rc.local文件,它在启动时运行(将字符串回显到文件),但是forever(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:没有这样的文件或目录

2 个答案:

答案 0 :(得分:0)

我想你还设置了执行位吗?

ls -l /etc/rc.local

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

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

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

答案 1 :(得分:0)

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

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