Search code examples
svnpleskpost-commitpost-commit-hook

How to create a SVN Hook post-commit on a Plesk 11 Server for a svn+ssh tunnel user?


On my Plesk 11 Server i create an subdomain: sub.domain.tld

For all the users i create a svn+ssh tunnel. All users committed through this tunnel.

Now i want to create SVN Hook so that every commit should be directly update into sub.domain.tld

I'm using this tutorial but i always get /bin/sh: /var/.../hooks/post-commit: Permission denied

I guess because domain and subdomain was created from Plesk itself.

How can i make my subversion be able to post-commit into a directory created by Plesk?


Solution

  • It doesn't matter how Subversion is served, the hooks all operate the same way on the server.

    Hooks are executed by the server. Therefore, you need to make sure that the hook itself has execute permission set, and that it is owned by the user who runs the SVN Server. Also, the environment is stripped clean when a hook is executed. So, the $PATH might not be set the way you want.

    Usually, when you see this type of error, it's due to one of these issues. My recommendation is to make a very simple hook (this is the Unix/Linux version):

    #! /bin/bash
    echo "The hook has executed" >&2
    exit 2
    

    This hook is guaranteed to fail which is what you want. When a hook fails, the output printed to STDERR is returned to the user. You should see something like this:

    The post-commit hook failed with the output of "The hook has executed"
    

    If you don't see that, you know that Subversion is failing to execute your hook, and it's not a problem with the hook. Check the things mentioned above: Is the execute bit on the hook? Is the hook (and the entire repository) owned by the user that executes the Subversion server process. (For example, usually apache, httpd, or wwwrun when running under Apache httpd.

    Since you're running under svn+ssh, you need to make sure that the GROUP ownership is the same group as your users, that the GROUP execute permission is set correctly, and that the UMASK for all of your users is set to 0002 and not to just 0022.


    Now, let's look at what you want:

    Now i want to create SVN Hook so that every commit should be directly update into sub.domain.tld

    It appears you want a particular working copy to be updated whenever someone commits a change. You can do this through a pre-commit hook, but I recommend you use Jenkins for this type of stuff.

    • It will allow you to skip the post-commit hook that may take a while to update. For example, you probably want to restart the server after the update. When the post-commit hook is running, no one else is allowed to make further changes. Plus, the user who made the commit must wait for the post-commit hook to run. Maybe the whole thing takes only 20 to 30 seconds, but imagine the user who has to wait for those 20 to 30 seconds while the post-commit hook is running.
    • It'll give you a bit more control. Whenever I do something like this, I have two server directories: My first one is the active directory which the server uses. My second one is the inactive directory which simply sits there and gets an update. When an update happens, I update the inactive directory, then restart my server and change the two directories. Now the former inactive directory which was updated is used by my server while my formally inactive directory waits for an update. This prevents a situation where someone makes a server request while my active server directory is in the middle of an update.
    • This will allow further expansion. For example, you might decide not all commits should update the server. Instead, the server is only updated when the user goes into Jenkins and requests it. Or, maybe when an update occurs, you want to run some tests. You certainly can't do that with a post-commit hook, but you could with Jenkins. Maybe you want to update several servers. Again, this is easier with Jenkins.