linux - Can git post-receive hook perform git pull on multiple servers?
巴扎黑
巴扎黑 2017-05-16 13:22:18
0
1
551

Environment Description

  1. Created a warehouse in the /home/work/ directory of Server A /home/work/my-project.git

  2. Clone /home/work/my-project.git to the website root directory /home/www/

  3. Configuredgit post-receive hook

#!/bin/bash

cd /home/www
env -i git pull

In this way, every time git push, the code can be updated to the /home/www directory of server A

Problem Description

If I clone /home/work/my-project.git on Server B to the directory /home/www/. Is there any way to go to Server A and Server B to perform git pull operations at the same time every time git push is executed?

My current approach is to add a crontab scheduled task on server B, and execute it in the /home/www/ directory every minute git pull, although this can also achieve the effect of automatic git push, but there is also a time difference.

Do you have any better practices?

巴扎黑
巴扎黑

reply all(1)
曾经蜡笔没有小新

If服务器A能通过ssh访问服务器B, you can add a line in git post-receive hook

rsync -az -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" /home/www/ <服务器B的IP>:/home/www/

After each git push, server A will clone /home/work/my-project.git to the website root directory /home/www/, and at the same time, it will synchronize /home/www/ to server B’s /home through rsync
/www/

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!