0

I'm trying to setup upstart to run with my Node js and Socket.io server.

/etc/init/quizens.conf

env NODE_BIN=/usr/bin/node
env APP_DIR=/root/quizens
env SCRIPT_FILE="quizens.js"
env LOG_FILE=/root/quizens.log
env RUN_AS="root"

start on filesystem
stop on shutdown

respawn
respawn limit 1 10

script
    touch $LOG_FILE
    chown $RUN_AS:$RUN_AS $LOG_FILE
    chdir $APP_DIR
    exec sudo -u $RUN_AS sh -c "$NODE_BIN $SCRIPT_FILE >> $LOG_FILE 2>&1"
end script

When I run start quizens in the log file I get Cannot find module fb.... altough if i simply start the server from command line it works. The modules are installed with -g and they reside in /usr/lib/node_modules

I can't find a problem while on my local machine it works like a charm, but not when putting it on a softlayer instance.

The difference is that the local machine Node is installed in /usr/local/bin/node not in /usr/bin/node. Is this the problem?

EDIT: Yesterday I added another IP for the instance. I don't know if this has anything to do with upstart...

2 Answers 2

0

Try removing sudo, it will likely mess your working dir. The script section is run as root already. Exec line could look like exec $NODE_BIN $SCRIPT_FILE >> $LOG_FILE 2>&1. You can also remove lines with touch and chown.

2
  • Tried your recommendations but it's still not working. same output in the log file. Aug 6, 2013 at 12:40
  • Then I guess Node is missing some environment variable it requires. Skim Node docs for what it wants. See differences in env in terminal, and env in script section.
    – Tuminoid
    Aug 8, 2013 at 5:32
0

Simple fix, just create a simlink:

sudo ln -s /usr/bin/nodejs /usr/bin/node

source

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .