I’ve followed the example listed at this site in remotely adding my files to my server, however, I’d like to have all files owned by the nginx:nginx user:group so that I can access the files from my browser after pushing the files.
How do I go about amending the post-receive hook so that nginx:nginx becomes the owner of the files/folders pushed to the remote ‘ubuntu` server?
I’ve tried the following post-receive hook, however, if the file is being amended I receive the error: remote: error: unable to unlink old 'index.html' (Permission denied), shell script here:
#!/bin/sh
GIT_WORK_TREE=/var/www/www.foo.com/htdocs
export GIT_WORK_TREE
git checkout -f
exec sudo chown -R nginx:nginx $GIT_WORK_TREE
Thanks advance for any help!
It is usually the result of a process not releasing those files (preventing the git checkout to do its jobs), as described in “Git Checkout warning: unable to unlink files, permission denied“.
But it could also be the result of your
sudocommand to have worked successfully once, making any future execution of your hook fail because it no longer has the right to checkout as the ‘git‘ user.If it is the case, your hook should
sudoasnginx:nginxyour current git command, instead ofchownthe end result (the web working tree).The OP confirms:
I suggests:
Which seems to solve the issue: