0

Goal: update /var/www with latest on svn commit.

ubuntu server 10.10, latest apache2, latest svn, location: /var/svn/[projectname]

To do this I created a simple post-commit script:

#!/bin/bash

#tests if www-data user runs this script on commit (which it does)
touch /tmp/test.log

#works when run from the command line (sudo ./post-commit) but not when run by www-data
sudo /usr/bin/svn update /var/www

To fix the issue of the second command not working as www-data I tried...

Editing: sudo visudo and added (at the end): www-data ALL=(ALL) NOPASSWD:ALL

Chowning: /var/www to www-data:www-data

Chmoding: all of /var/www to 777

Still no luck... any ideas?

1
  • What error are you getting? cron should send any stderr output by email. Commented Dec 3, 2010 at 1:28

2 Answers 2

1

What if you run this:

  su - www-data -c '/usr/bin/svn update /var/www'

(The sudo is not needed if /var/www/ is 777 and owned by www-data..)

As the root user? (then it suid()s as www-data and run the command). It should give more information on what does actually fail.

Or, you could try logging the svn update output from your post-commit hook:

/usr/bin/svn update /var/www &> /tmp/my-svn-update.log

I think that these two tests should give you more informations on what happened.

SIDE NOTE: I'm not sure you really want to take the risk of having www-data able to run any command as the root user.. If you absolutely need to have it run svn as root (I don't see the point there, but it could be), just use this in your /etc/sudoers:

www-data ALL=NOPASSWD: /usr/bin/svn
Sign up to request clarification or add additional context in comments.

Comments

0

I went first with the logging mechanism you suggested and that helped fix it! Thank you!

The outputted error had something to do with an filename in the repro which couldn't be converted to UTF-8. I deleted the file and it worked. But why it worked when calling post-commit directly... I've no clue.

BTW, I was mistaken about it being bash (it was sh) so I had to change &> to 2>

Also, I deleted the checked out files, reset the permissions and owner back to normal on /var/www and then checked them out again.

my final sudoers line:

www-data ALL=NOPASSWD:/usr/bin/svn update /var/www

Thanks so much for the help!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.