1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sshpassを使用してsvnサーバから別のホストにsvn updateでデプロイする

Posted at

sshpassを使用して、subversionサーバから、別のホストにsvn updateを使用してデプロイします。
筆者環境ではOSはCentOS6.7を使用しました。

sshpassは便利ですが、セキュリティ上の問題がある場合は、公開鍵認証を使用してください。

  • sshpassを両方のサーバにインストールします。(epelリポジトリにあります)
  • svnサーバのリポジトリ内のhooksディレクトリにある、post-commit.tmplをpost-commitに変更します。
  • 下記のスクリプトを貼り付けて、変数に必要なユーザー名とパスワード、サーバ名を入れます。
  • デプロイされる側のホストの、sshpass接続ユーザの".subversion/config"ファイルの[auth]セクションに、以下のようにパスワード保存の問い合わせをしない設定を入れます。
~/.subversion/config
[auth]
store-passwords = no
store-plaintext-passwords = no
  • post-commitのスクリプトに実行権限を付与します。
  • 実際にリポジトリにコミットしてテストします。

下記のデフォルトでは、post-commitのログは/var/log/svn/post-commit.logに出力しています。

/var/svn/repos/target_repos/hooks/post-commit
REPOS="$1"
REV="$2"

# Deploy target server's info.
DEPLOY_SERVER="user_name@target.server"
DEPLOY_SERVER_PASS="password"
# Sub version user's info for svn update.
SVNUSER="svn_user_name"
SVNPASS="svn_user_pass"
SVN_UPDATE_DIR=/var/www/html/svn_update_dir/
HOOK_BRANCH="trunk"
SVNOPTS="--username $SVNUSER --password $SVNPASS"
# Log file path.
LOG=/var/log/svn/post-commit.log

# Pick up changed files.
CHANGED_FILES=`svnlook changed -r $REV $REPOS`

# svn update on target server.
# Affect only hook branch.
if echo $CHANGED_FILES | grep $HOOK_BRANCH > /dev/null; then
    echo "--- `date` deploy started." >> $LOG
    echo "deploy target server: $DEPLOY_SERVER" >> $LOG
    echo "repos and rev: $REPOS $REV" >> $LOG
    #svn update on server using sshpass.
    RESULT=`sshpass -p $DEPLOY_SERVER_PASS ssh -o StrictHostKeyChecking=no $DEPLOY_SERVER svn $SVNOPTS update $SVN_UPDATE_DIR`
    echo "svn update result: $RESULT" >> $LOG
    echo "--- `date` deploy ended." >> $LOG
fi
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?