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

Environment Description

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

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

  3. Configuredgit post-receive hook

#!/bin/bash cd /home/www env -i git pull

In this way, every timegit push, the code can be updated to the/home/wwwdirectory ofserver A

Problem Description

If I clone/home/work/my-project.gitonServer Bto the directory/home/www/. Is there any way to go toServer AandServer Bto performgit pulloperations at the same time every timegit pushis executed?

My current approach is to add acrontab scheduled taskonserver B, and execute it in the/home/www/directory every minutegit pull, although this can also achieve the effect of automaticgit 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!