2

Say I have a decent git server(source code repos). I want to push the code to 50 websevers, I can do the following in sequence:

#!/bin/bash
for i in {1..50}
do 
    ssh root@websever$i '(cd /var/www/project; git pull)'
done

Question: Is there an easy way to push the code to 50 websevers in parallel? Thanks.

nkhuyu
  • 840
  • 3
  • 9
  • 23

3 Answers3

2

This similar question might be relevant (suggest Bash sub-shells or GNU parallel utility).

I'm assuming that you are wanting to use git for "installing" code to go live to 50 boxes, and that you might have to separately "deploy" that code with a web server restart.

The suggestion I would make is that it might not seem like it now depending on the type of project, but if this project grows, it will become advantageous to build "release artifacts" such as a versioned tar-ball or zip file, rather than pulling from a branch head all the time. The advantage is that you can create binaries that represent release artifacts, and you can easily roll back changes if things go wrong.

(Aside: you might want to use

ssh root@webserver$i "(cd /var/www/project; git pull)" 

as a one liner.)

Community
  • 1
  • 1
nowucca
  • 474
  • 2
  • 3
1

You can make 2 scripts

dogitjob.sh:

#!/bin/bash
ssh root@webserver$1 "(cd /var/www/project; git pull)" 

main.sh

#!/bin/bash
for i in {1..50}
do 
    bash dogitjob.sh $i &
done

these are very basic scripts , just for showing idea

aloso there are some utils like dsh or pssh, they are described here

Vlad Nikitin
  • 1,929
  • 15
  • 17
  • dogitjob.sh won't run the pull on webserverN; it will attempt to start an interactive session to webserverN and, when that process dies, it will run `cd` and `git pull` _on the current machine_. – Magnus Bäck Feb 01 '14 at 20:47
  • 1
    Also, dogitjob.sh must use `$1`, not `$i`. – Magnus Bäck Feb 02 '14 at 16:38
1

If you want to deploy changes and upgrades to your software across multiple servers as fast as possible, you should look at BitTorrent to distribute files to a large amount of servers.

You could read the brief overview of Twitter's approach to distributed, large-scale code deployment and checkout Murder

Michael Ver
  • 402
  • 3
  • 5