简体   繁体   English

rc.local 脚本手动运行,但在启动时失败……是什么导致的?

[英]rc.local script runs manually but fails on startup…what gives?

I can run my /etc/rc.local file manually, it runs on startup (echoing a string to a file), but the forever (npm package) is failing for some reason.我可以手动运行我的 /etc/rc.local 文件,它在启动时运行(将字符串回显到文件),但是永远(npm 包)由于某种原因失败了。 I'm running the Amazon Linux AMI on an EC2 instance if that helps.如果有帮助,我正在 EC2 实例上运行 Amazon Linux AMI。

Where can I look to understand why it's failing or can you tell me what I'm doing wrong?我在哪里可以了解为什么它失败了,或者你能告诉我我做错了什么吗?

#!/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 &

Ok, things seems to be getting a bit better, I updated my rc.local file to this:好的,事情似乎变得更好了,我将 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 &

And /tmp/rc.local.log is telling me this: /tmp/rc.local.log 告诉我这个:

/usr/bin/env: node: No such file or directory /usr/bin/env: node: 没有那个文件或目录

I suppose you still have the execution bits set?我想你仍然设置了执行位?

ls -l /etc/rc.local

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

Also, the script or tool /usr/local/bin/forever must also be executable ('x' bits set appropriately), but that you would have detected when you test manually.此外,脚本或工具/usr/local/bin/forever也必须是可执行的('x' 位设置适当),但您在手动测试时会检测到。

The only reason why I could imagine that this would not work on startup is something that it requires is not ready by then and thus the startup of the forever tool fails.我可以想象这在启动时不起作用的唯一原因是它需要的东西到那时还没有准备好,因此永远工具的启动失败。 Is forever a script?永远是剧本吗? If so maybe you could show us what's in there?如果是这样,也许你可以告诉我们里面有什么?

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

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

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

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