1

I'm trying to run a node.js script at boot using crontab.

Here's the command

/usr/local/bin/forever -c /usr/local/bin/node start /var/www/html/lights.js >/var/log/lights 2>&1 &

At reboot, the cron log says that the command was executed, but the lights log shows this

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

Running the command works, just not when cron runs it.

2 Answers 2

3

To start a linux deamon, server or app at boot is normally used a script in /etc/init.d.

Take a look at this script for starting node.js in Centos: https://gist.github.com/nariyu/1211413

After doing your own version of it with your file, you may "activate" it to run at boot with: chkconfig nodejs on After that you may also be able to use service nodejs start or service nodejs stop to start or stop it.

0
3

cron uses a very restrictive PATH by default. You'll need to either have cron run a script that changes PATH, or set PATH= in your crontab file. See this question and answer here for details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.