Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a simple upstart script:

start on started network-services

respawn
respawn limit 100 5

setuid www-data

exec node /var/testapp/app.js >> /var/log/testapp.log 2>&1

post-start exec echo "Server was (re)started on $(date)" | mail -s "Crashing Server (re)starting" admin@sample-test.com

but because I'm running the node app as 'www-data', I don't have write permissions on testapp.log.

What is the best approach to address that?

I would rather not pre-create the log file with 'www-data' as it's owner, because I would like as few steps as possible for the setup. I'd also rather not run the app as 'www-data' with sudo:

exec sudo -u www-data node /var/testapp/app.js >> /var/log/testapp.log 2>&1

because when I do so, root is also running the process. Maybe I'm wrong, but I see that as a security issue. If it's not a security issue - please enlighten me.

share|improve this question
    
Did you solve it? I have same problem – igo Oct 13 '13 at 16:01
    
@igo - i solved it by running the exec like so: exec sudo -u www-data node /var/testapp/app.js >> /var/log/testapp.log 2>&1 – gilmad Oct 14 '13 at 18:03

You can just create another directory in the log dir and give www-data ownership:

sudo mkdir /var/log/testapp
sudo chown www-data:www-data /var/log/testapp

/var/log/testapp is now writable by www-data, so then in upstart script you would have:

exec node /var/testapp/app.js >> /var/log/testapp/app.log 2>&1
share|improve this answer

You must log in to answer this question.

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