Created
January 21, 2014 13:23
-
-
Save mezis/8539934 to your computer and use it in GitHub Desktop.
Restart servers in a staggered manner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/config/deploy.rb w/config/deploy.rb | |
index 73fc910..594322c 100644 | |
--- i/config/deploy.rb | |
+++ w/config/deploy.rb | |
@@ -65,7 +65,7 @@ end | |
desc 'restart' | |
deploy.task :restart, :roles => :web do | |
- run "touch #{current_path}/tmp/restart.txt" | |
+ run "bash -c 'sleep $(( $RANDOM / 100 ))' ; date ; touch #{current_path}/tmp/restart.txt" | |
end |
The thing is now testing that everything is fine has to be done on targeted servers.
Not sure I get your point Stefan. All servers (with role web
) are targeted by this.
Plus, the task doesn't return until each has restarted—which does add a 5min delay in your deploy, purposedly.
But then you can have broken servers for 5 minutes untill the last one is finished.
Why broken? They're just restarted with a new version of the code which is fine. The only issue is that for 5 minutes users may get 1 page from the old code and 1 page from the new
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$RANDOM
is a magic Bash variable that returns an positive signed short (0-32767), so dividing it by 100, each server will restart randomly over roughly 5 minutes.Left as an exercise to the reader: add a comment and make it the default for production deploys (don't want to do that on staging)