linuxgitnginxpermissionsgitolite

Failed to archieve Gitolite (Git) and nginx webserver access webspace at the same time



Starting point:

I want to update the webspace as git user with post-receive to a www-data directory. I had it archived before I installed Gitolite, but it doesn't seem to work the same way as it did before (or I am missing something). To make it clear: post-receive is executed after pushing (which it's normally not on Gitolite) ... was a hard time too to archive that.

Edit: To make it clear: I want to archive that Git and www-data can access and modify the same files.


What Ive tried:


What Ive noticed so far:


The code (not that it would be important, but just to list everything):

    #!/bin/sh
    GIT_WORK_TREE=/var/www/webspace git checkout -f

Maybe Im just missing something, but please help me.


Solution

  • Add user (git in my case) to group of webspace (www-data for me)

    sudo usermod -a -G www-data git 
    

    If you were logged in as user logout to reload the group.

    logout
    #or
    exit
    #or
    CTRL+A+D
    

    (If you want to recheck the group login as this user and type "groups" to see the groups the user is in)


    Make sure the webspace is owned by the correct group. For me:

    sudo chown www-data:www-data -R /var/www/webspace
    

    (If you want to recheck this you can go in the directory and type "ls -g")


    In my case I had to modify my "post-receive" a bit, because the permissions were always -rw----- after checking out, so here is my "post-receive":

    #!/bin/sh
    GIT_WORK_TREE=/var/www/webspace git checkout -f    #default line to checkout
    chmod -R a+r /var/www/webspace     #added by me because of permission issues
    

    For convenience I had my "post-receive" in the repo directory (/home/git/repositories/repo/hooks/post-receive). The docs tell you to create a new folder (/home/git/local/specific-hooks/repo/post-receive (but they tell to name it on your own))

    *All paths, names, groups and permissions written above only apply to me. They may differ for you installation.


    What really solved my problem: