I'm trying to deploy my sites on my company's semi-managed vps server using this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vpsIt works on my own Digital Ocean servers without change, but things are set up differently on my company server.The public_html folders need to be owned by the whm account user, or you get 500 errors. But the git user needs to own the public_html folder for this method to work. So I'm modifying the post-receive script to include commands to change the owners, but it doesn't seem to work. What am I doing wrong?#!/bin/sh# REPLACE *** WITH ACCOUNT USERNAME# Change owner of html folder to gitfind /home/***/public_html -user root -exec chown -R git:git {} + 2>>logfileecho Changed owner to git.# Update html folder with git push contentsgit --work-tree=/home/***/public_html --git-dir=/home/***/repo/live.git checkout -fecho Updated public html.# Restore ownership of directoriesfind /home/***/public_html -user root -exec chown -R ***:*** {} + 2>>logfilefind /home/***/public_html -user root -exec chown ***:nobody {} + 2>>logfileecho Changed owners back.
I'm trying to deploy with git to a semi-managed vps, need to write a script to change owners
shell;shell script;ssh;scripting;git
I would do away with find; since you know where the directory is, you should just deal with it directly. The find command introduces a new condition that could fail.In either case, you are not terminating the find command, which could be a problem.This might work better:#!/bin/sh# REPLACE foo WITH ACCOUNT USERNAME# Change owner of html folder to gitchown -R git:git /home/foo/public_html || echo $date I failed. >> /tmp/foo.logecho Changed owner to git.# Update html folder with git push contentsgit --work-tree=/home/foo/public_html --git-dir=/home/foo/repo/live.git checkout -f || echo $date Git failed. >> /tmp/foo.logecho Updated public html.# Restore ownership of directorieschown -R foo:bar /home/foo/public_html chown foo:nobody /home/foo/public_htmlecho Changed owners back.