Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I got my own linode server the other day and moved a small nodejs / express I was playing around with over from an aws linux. Everything works great, but if I launch the app with upstart it doesnt run with the right permissions and can't write files to disk. I tried all kinds of variations of the upstart script, as root, as my username, www-data and nothing works. I set the public directory of express to 777 even just as a test but no luck. I start my upstart job with sudo start now-images-manager. When I run ps -ef I get the following output:

root     25150     1  0 11:26 ?        00:00:00 sudo node /home/myusername/sites/now-images-manager/app.js
root     25151 25150  0 11:26 ?        00:00:03 node /home/myusername/sites/now-images-manager/app.js

Here is my upstart script:

#!upstart
description "now-images-manager startup script"
author      "me@me.com"

start on startup
stop on shutdown

script
    export HOME="/root"
    echo $$ > /var/run/now-images-manager.pid
    exec sudo node /home/myusername/sites/now-images-manager/app.js >> /home/myusername/sites/now-images-manager/now-images-manager.sys.log 2>&1
    # exec sudo -u myusername /usr/bin/node /home/myusername/sites/now-images-manager/app.js >> /home/myusername/sites/now-images-manager/now-images-manager.sys.log 2>&1
end script

pre-start script
    # Date format same as (new Date()).toISOString() for consistency
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/now-images-manager.sys.log
end script

pre-stop script
    rm /var/run/now-images-manager.pid
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/now-images-manager.sys.log
end script

Here is a sample from the log:

downloadFileFromURL  { [Error: ENOENT, open 'public/images/tumblr_m9h1uh4KSi1qzl9k6o1_500.jpg']
  errno: 34,
  code: 'ENOENT',
  path: 'public/images/tumblr_m9h1uh4KSi1qzl9k6o1_500.jpg' }

When I start the app with node app.js in the shell it works perfectly fine.

share|improve this question
    
Were you able to sort this out? –  TYRONEMICHAEL Sep 25 at 7:56

1 Answer 1

I found the issue. If you creating directories using your node app, you first need to cd into your node app's directory. So my upstart script looks like the following:

script
    export HOME="/var/www"
    cd $HOME/mywebsite/
    exec node index.js  >> /var/log/node.log 2>&1
end script

You can test this, by moving up a directory and then trying to run your node application. It should throw the same error as your upstart script before the changes made above.

share|improve this answer

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.