gitを使用してセカンダリ管理vpsに展開しようとしていますが、所有者を変更するスクリプトを作成する必要があります。

gitを使用してセカンダリ管理vpsに展開しようとしていますが、所有者を変更するスクリプトを作成する必要があります。

このチュートリアルを使用して、会社の反管理型vpsサーバーにWebサイトを展開しようとしています。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."

おすすめ記事