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


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 limit 1 10

    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...


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.

  • Tried your recommendations but it's still not working. same output in the log file. – Tiberiu Maxim Aug 6 '13 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 '13 at 5:32

Simple fix, just create a simlink:

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


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.