f0fa2665

My goal here was to update a dev server anytime I commit a file. The simpliest way to do that seemed to create a post-commit hook. The difficulty though, came from file ownership and user issues. Basically, the post-commit script is executed as Apache : www-data on debian. And this user, on my setup, didn’t have the rights to update … I tried to use su but that failed with “su can only be run in the terminal”. I installed and tried with sudo and that failed with “sudo no tty present and no askpass program specified”.

So, here is the solution.

Go to your repository (ie /var/repository/) and cd into the hooks directory

1
cd /var/repository/my_project/hooks

You will see a post-commit.tmpl file. That is an example Create a post-commit file and enter the following

1
2
3
vi post-commit
#!/bin/sh
sudo -u your_user /usr/bin/svn update /var/www/project/ --username your_svn_user --password your_svn_password

Now, make sure this file can be executed by Apache

1
2
chown www-data:www-data post-commit
chmod 744 post-commit

Time to check the sudo part of this

1
aptitude install sudo #if you do not have it already

And give Apache the right to sudo to use svn without password

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#as root
cd /etc/

# give root editing rights
chmod 740 sudoers
vi sudoers

#add this line
%www-data ALL=(ALL) NOPASSWD:/usr/bin/svn

# exit
:wq

#restore the rights
chmod 440 sudoers

That was it for me.

An interesting alternative solution.

Filed under: Système, Terminal

Tagged with: , , , , ,

Liked this page?

Tweet it

Subscribe to the RSS feed or sign up for the newsletter now.

Posts related to SVN AUTO UPDATING A DEV SERVER ON COMMIT

1 Comment to "SVN AUTO UPDATING A DEV SERVER ON COMMIT"

  1. Comment by Amol on April 30, 2015 at 11:55 am Reply

    Highly insecure way, as you are giving apache user with sudo permission !

Name (required)

Email (required)

Website

Leave a Reply

  • About Me


    photo of Samantha Halfon Samantha Halfon
    Software Engineer
    blueKiwi software
    Paris, France
    I enjoy playing with my computer(s), listening to Bob Dylan (and related artists) and watching movies (especially if they were directed by Martin Scorsese or John Cassavetes). Sometimes, I play a little guitar... If not doing any of the above, I am either riding a small red bike around Paris, or, making videos. About my videomaking please check out World Wide Angle and its blog.