1

I have a website up and running with nginx, and I have some content in my website that I want to manage with git so that others can collaborate.

Let us say that have a user named alice and that the root of the website is located somewhere within alice's home directory, as in /home/alice/website/index.html

Let us also assume that I have set up a git server via gitolite for access-control, the usage of which requires setting up a dummy user that we will call git. There are good reasons for this user being a separate one from alice.

I want alice's website to be able to show the content of some git repository web_repo.git, the origin of which is to be found in /home/git/web_repo.git, as the documentation for gitolite requires.

My first idea is to run a post-receive hook in the repository to sync it with some subdirectory of /home/alice/website, but that demands user git copying files into other user's (alice) home directory, which ends up in file permissions error.

There are certain constraints in my build that require the website to be hosted within alice's home directory, and I can't think of a secure and elegant solution to this problem.

I have just started managing this small server and I would kindly appreciate any insights.

2
  • Why does it have to be the home directory of alice? Place the web root in /var/www where it belongs, and create a group. Put both users in that group, and set appropriate permissions on the web root directory.
    – Panki
    Aug 5 at 17:36
  • cronjob for user alice to cd /home/alice/website/ && git pull? not quite as good as a post-receive hook, but updates should be reasonably fast. (btw, remember to deny access to .git/ via the web server)
    – cas
    Aug 6 at 1:13
1

There's thousands way of doing this ! I would proceed the following way:

First, i create a small shell script, run as user alice in background (tmux, screen, or event initd/systemd service). This script would continuously :

  1. Monitor a file in /tmp/, for example /tmp/new_commit.
  2. When the file appears, then do the git pull plus eventually a chmod -r if needed.
  3. Remove file /tmp/new_commit.
  4. Go back to step 1.

Then i would write a git post-receive hooks on server-side to create this file on new commit and chmod 666 it.

If you want to go more "professionnal" about that, i suggest you to look to devops and CI stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.