git을 사용하여 반관리형 vps에 배포하려고 하는데 소유자를 변경하는 스크립트를 작성해야 합니다.

git을 사용하여 반관리형 vps에 배포하려고 하는데 소유자를 변경하는 스크립트를 작성해야 합니다.

이 튜토리얼을 사용하여 회사의 반관리형 vps 서버에 웹사이트를 배포하려고 합니다.https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps

내 Digital Ocean 서버에서는 아무런 변경 없이 작동하지만 내 회사 서버에서는 설정이 다릅니다.

public_html 폴더는 whm 계정 사용자가 소유해야 합니다. 그렇지 않으면 500 오류가 발생합니다. 하지만 이 방법이 작동하려면 git 사용자는 public_html 폴더를 소유해야 합니다. 그래서 소유자를 변경하는 명령을 포함하도록 수신 후 스크립트를 수정하고 있는데 작동하지 않는 것 같습니다. 내가 뭘 잘못했나요?

#!/bin/sh

# REPLACE *** WITH ACCOUNT USERNAME
# Change owner of html folder to git
find /home/***/public_html -user root -exec chown -R git:git {} + 2>>logfile
echo "Changed owner to git."

# Update html folder with git push contents
git --work-tree=/home/***/public_html --git-dir=/home/***/repo/live.git checkout -f
echo "Updated public html."

# Restore ownership of directories
find /home/***/public_html -user root -exec chown -R ***:*** {} + 2>>logfile
find /home/***/public_html -user root -exec chown ***:nobody {} + 2>>logfile
echo "Changed owners back."

답변1

찾기를 취소하겠습니다. 이제 디렉토리가 어디에 있는지 알았으므로 직접 처리해야 합니다. find 명령은 실패할 수 있는 새로운 조건을 도입합니다.

두 경우 모두 문제가 될 수 있는 find 명령을 종료하지 않습니다.

이것이 더 잘 작동할 수 있습니다:

#!/bin/sh

# REPLACE foo WITH ACCOUNT USERNAME
# Change owner of html folder to git
chown -R git:git /home/foo/public_html || echo "$date I failed." >> /tmp/foo.log
echo "Changed owner to git."

# Update html folder with git push contents
git --work-tree=/home/foo/public_html --git-dir=/home/foo/repo/live.git checkout -f || echo "$date Git failed." >> /tmp/foo.log
echo "Updated public html."

# Restore ownership of directories
chown -R foo:bar /home/foo/public_html 
chown foo:nobody /home/foo/public_html
echo "Changed owners back."

관련 정보