Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a problem with the node_module-path. Can someone let me know what I'm doing wrong?

Running

exec sudo -u www-data /usr/bin/node /etc/node/app.js

gives me

Error: Cannot find module 'connect'

I have this config (/etc/init/applicationserver.conf):

start on started mountall
stop on shutdown

respawn
respawn limit 99 5

script
    export HOME="/"
    export NODE_PATH="/usr/lib/node_modules"

    exec sudo -u www-data /usr/bin/node /etc/node/app.js >> /var/log/applicationserver.log 2>&1
end script

post-start script

end script

It seems like it can't find the modules installed. I've verified that connect is under /usr/lib/node_modules and if I export NODE_PATH from root or my account it works fine.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Hmm, not the best way to be starting something in general. A wrapper script with the correct ownership could do the same work without sudo.

You're problem is in the use of sudo, regardless of the context as an upstart job. The environmental vars you're defining aren't being passed on. Add the '-E' switch to sudo to correct this.

If you used a wrapper owned by www-data to start that process you wouldn't have this problem because you wouldn't have needed sudo. There are lots of example jobs that create vars and pass them on to the new child process. It's a basic property of fork/clone.

share|improve this answer
    
I'm all ears on if there is a better way to start it. Any suggestions? I'm quite the noob on these things. –  Asken Nov 20 '11 at 17:10
    
Btw, the -E made it work. When thinking of it, it seems logic that the env vars don't follow by default. –  Asken Nov 20 '11 at 17:20
1  
How about this? cat js-wrapper.sh #!/bin/sh /usr/bin/node /etc/node/app.js >> /var/log/applicationserver.log 2>&1 chown www-data:root js-wrapper.sh and run that instead? –  ppetraki Nov 20 '11 at 18:42
    
I'll do that. Just a final question. why www-data:root and not www-data:www-data or it doesn't matter? –  Asken Nov 21 '11 at 9:25
1  
Just not leaving it to chance. This is basic Unix system administration and there is plenty of documentation on the subject. tldp.org/LDP/sag/html/index.html –  ppetraki Nov 21 '11 at 14:10
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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