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.

1
  • This code will execute the cd and the git pull part on the current machine! Commented Feb 2, 2014 at 18:48

3 Answers 3

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.)

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

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.
Also, dogitjob.sh must use $1, not $i.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.