2

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. I'm running the Amazon Linux AMI on an EC2 instance if that helps.

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:

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

/usr/bin/env: node: No such file or directory

SomethingOn
  • 9,813
  • 17
  • 68
  • 107
  • 2
    I added a symlink for node as per this question/answer and it looks like everything is working now :D http://stackoverflow.com/questions/20061529/sublime-text-coffeescript-build-system-env-node-no-such-file-or-directory – SomethingOn Aug 05 '14 at 05:28

2 Answers2

0

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.

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?

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
  • 1
    forever is a nodejs module. It was installed globally. Is there a log for rc.local that might indicate what's failing? – SomethingOn Aug 05 '14 at 03:15
  • 1
    In most cases, the output while initializing ends up in `/var/log/syslog`, except the kernel boot process which is put in `/var/log/boot.log`. – Alexis Wilke Aug 08 '14 at 11:04
0

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

because 'use --login' could find the node enviroment. --login means Provide an environment similar to what the user would expect had the user logged in directly