第9å ã¡ã³ããã³ã¹ãã¼ã¸ã¸ã®åãæ¿ã
2008/06/03
ä»åã¯ãCapistrano ã® deploy:web:disable
㨠deploy:web:enable
ã¿ã¹ã¯ã«ã¤ãã¦ã
cap -T
ã§è¡¨ç¤ºããã説æã«ããã°ãããããã®ã¿ã¹ã¯ã®ç®çã¯æ¬¡ã®éãï¼
deploy:web:disable
-- 訪åè ã«ã¡ã³ããã³ã¹ãã¼ã¸ãè¦ãããdeploy:web:enable
-- åã³ã¢ããªã±ã¼ã·ã§ã³ãWebã¢ã¯ã»ã¹å¯è½ã«ããã
ãã¼ãã便å©ããã§ããããããã ãã§ã¯ä½ãã©ããªãã®ãä»ã²ã¨ã¤ãã³ã¨æ¥ãªããã½ã¼ã¹ã³ã¼ããè¦ã¦ã¿ããï¼ä¸é¨ãçç¥ï¼ã
namespace :deploy do namespace :web do task :disable, :roles => :web, :except => { :no_release => true } do require 'erb' on_rollback { run "rm #{shared_path}/system/maintenance.html" } reason = ENV['REASON'] deadline = ENV['UNTIL'] template = File.read(File.join(File.dirname(__FILE__), "templates", "maintenance.rhtml")) result = ERB.new(template).result(binding) put result, "#{shared_path}/system/maintenance.html", :mode => 0644 end task :enable, :roles => :web, :except => { :no_release => true } do run "rm #{shared_path}/system/maintenance.html" end end end
deploy:web:disable
ã¿ã¹ã¯ããã£ã¦ããã®ã¯ãè¦ããã«ãã¡ã³ããã³ã¹ãã¼ã¸ã¨ãã¦è¡¨ç¤ºããã HTML ææ¸ã ERB ã§çæãã¦ãããã #{shared_path}/system/maintenance.html
ã¨ãããã¡ã¤ã«ã«æ¸ãè¾¼ããã¨ãããã¨ã ã
ã¡ã³ããã³ã¹ãã¼ã¸ã®ãã³ãã¬ã¼ãã¨ãã¦ã¯ãmaintenance.rhtml
ãç¨æããã¦ãããFile.dirname(__FILE__)
ã¯ããã®ã½ã¼ã¹ã³ã¼ãã®ãããã£ã¬ã¯ããªã ãããCapistrano ã®ã¤ã³ã¹ãã¼ã«ãã£ã¬ã¯ããªï¼ç°å¢ã«ãã£ã¦ç°ãªããã/usr/lib/ruby/gems/1.8/gems/capistrano-2.3.0/ ãªã©ï¼ã®ä¸ã® lib/capistrano/recipes/templates/maintenance.rhtml
ã¨ãããã¨ã«ãªãããã³ãã¬ã¼ããæå®ããå¤æ°ã¯ç¨æããã¦ããªãã®ã§ãç¬èªã®ã¡ã³ããã³ã¹ãã¼ã¸ãç¨æããããã°ï¼ãã¡ãããç¨æãããããï¼ããã®ã³ã¼ããåèã«èªåã§ã¿ã¹ã¯ãæ¸ãã¦ãconfig/deploy.rb
ã«è¿½å ããã
ããã¦ãdeploy:web:enable
ã¿ã¹ã¯ã¯ããã®ãã¡ã¤ã«ãæ¶ãã
é常ãshared_path
ã¯å¤æ° :deploy_to
ã§æå®ãããã£ã¬ã¯ããªã®ä¸ã«ãã shared
ãã£ã¬ã¯ããªã§ãããã¤ã¾ãã/var/rails/ballad
ã«ãããã¤ãããªãã/var/rails/ballad/shared/system/maintenance.html
ãåé¡ã®ãã¡ã¤ã«ã«ãªãã
ãã¦ããã®ãã¡ã¤ã«ãåå¨ããã°ãããã ãã§è¨ªåè ã«ã¡ã³ããã³ã¹ãã¼ã¸ãè¦ããããã®ã§ããã°è©±ã¯ç°¡åã ããããã§ã¯ãªãã
Apache ã® mod_rewrite ã®ãã£ã¬ã¯ãã£ãã¨å°ãæ ¼éããå¿ è¦ãããã
ç§ã¯ãã® mod_rewrite ã¨ããæåãè¦ãã¨ããæ鬱ã«ãªããmod_rewrite ã¯ã¹ã¤ã¹è£½ã®ã¢ã¼ãã¼ãã¤ãã§ãããé»éè¡(voodoo)ã§ããï¼Apache module mod_rewriteï¼ãä½ã§ãè¨å®ã§ãã¦æè»ã ãããã®å¥å¦ãªæ§æãç§ãå¹»æããã
ããããã
ä½ã¯ã¨ãããã次ã®ããã« httpd.conf
ã«æ¸ãã¨ãdeploy:web:disable
ã¿ã¹ã¯ã使ããããã«ãªãã
<VirtualHost *:80> ServerName ballad.example.com DocumentRoot /var/rails/ballad/current/public ErrorLog /var/log/httpd/ballad-error_log CustomLog /var/log/httpd/ballad-access_log combined env=!nolog <Directory /var/rails/ballad/current/public> Order Deny,Allow Allow from All </Directory> RewriteEngine On RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{REQUEST_URI} !^/images/ RewriteCond %{REQUEST_URI} !^/javascripts/ RewriteCond %{REQUEST_URI} !^/stylesheets/ RewriteRule ^.*$ /system/maintenance.html [L] RewriteRule ^/(images|javascripts|stylesheets)/(.*)$ /$1/$2 [L] ProxyRequests Off ProxyPass / balancer://ballad_cluster/ <Proxy balancer://ballad_cluster/> BalancerMember http://127.0.0.1:3000 BalancerMember http://127.0.0.1:3001 BalancerMember http://127.0.0.1:3002 BalancerMember http://127.0.0.1:3003 </Proxy> </VirtualHost>
å°ãé»éè¡ã®èª¬æã試ã¿ããã
ã¾ããRewriteEngine On
㧠mod_rewrite ãæå¹ã«ããã
次ã«ãRewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
ã§ã
ãã
%{DOCUMENT_ROOT}/system/maintenance.html
ã¨ãããã¡ã¤ã«ãåå¨ããã°
ã¨ããæ¡ä»¶ã表ãã%{DOCUMENT_ROOT}
ã«ã¯ãä¸ã®æ¹ã§å®£è¨ãã¦ããå¤ /var/rails/ballad/current/public
ãåãè¾¼ã¾ããã
ç¶ã3è¡ã® RewriteCond ã¯
/images ã¾ã㯠/javascripts ã¾ã㯠/stylesheets ãã£ã¬ã¯ããªã«ãããã¡ã¤ã«ã¸ã®ã¢ã¯ã»ã¹ã§ãªããã°
ã¨ããæ¡ä»¶ã表ããURIãã¹ã®ãã¿ã¼ã³ã®åã«ãã !
ã¯å¦å®ã示ãã
ãã®æ¬¡ã® RewriteRule ^.*$ /system/maintenance.html [L]
ã¯ã
æ£è¦è¡¨ç¾ã§
^.*$
ã«è©²å½ãããã¹ã/system/maintenance.html
ã«æ¸ãæãã
ã¨ããæå³ã§ããããã®æ£è¦è¡¨ç¾ã¯ãããããã¹ã«è©²å½ããã®ã§ãè¦ããã«ãã¹ã¦ã®ã¢ã¯ã»ã¹ã«å¯¾ãã¦ã¡ã³ããã³ã¹ãã¼ã¸ã表示ããããã¨ã«ãªãã
ãã®è¡ã®æ«å°¾ã«ã¤ãã¦ãã [L]
ã¯ããã以ä¸URLã®æ¸ãæãããããªãã¨ããæå³ã®ãã©ã°ã§ãããã¡ãªã¿ã«ããLãã¯ãLast ruleãã®ç¥ã ããã ã
ãã®æ¬¡ã® RewriteRule ^/(images|javascripts|stylesheets)/(.*)$ /$1/$2 [L]
ã¯ã
/images ã¾ã㯠/javascripts ã¾ã㯠/stylesheets ãã£ã¬ã¯ããªã«ãããã¡ã¤ã«ã¸ã®ã¢ã¯ã»ã¹ã«ã¤ãã¦ã¯ããã®ã¾ã¾è¿ã
ã¨ãããã¨ã§ããããã®è¡ã«ã [L]
ãã©ã°ãä»ãã¦ããã®ã§ããããã®ãã£ã¬ã¯ããªã«ãããã¡ã¤ã«ã¸ã®ã¢ã¯ã»ã¹ã¯ã常ã«ï¼ã¡ã³ããã³ã¹ä¸ãã©ããã«ãããããï¼Apache èªä½ãå¦çãããã¨ã«ãªããããã¯ãã¡ã³ããã³ã¹ãã¼ã¸ã«ãç»åçã表示ã§ããããã«ããããã§ããããRails ã¢ããªã±ã¼ã·ã§ã³ã¸ã®è² è·ãæ¸ããã¨ããå¹æãããã
ã¨ããã®ããã«èª¬æããã¦ã¿ãã°ãä½ã®ãã¨ã¯ãªãã®ã§ããããmod_rewrite ã®ããã¥ã¡ã³ããèªãã®ã¯éª¨ãæããããè¦å´ã¯è²·ã£ã¦ã§ããããã座å³ã®éã¨ããæ¹ã«ã¯ãå§ãã ã
ProxyRequests Off
以ä¸ã®è¨è¿°ã¯ãApache ããã¼ããã©ã³ãµï¼ãªãã¼ã¹ãããã·ï¼ã¨ãã¦å©ç¨ããããã®ãã®ã§ãããä»åã®è©±ã¨ã¯ç´æ¥ã¯é¢ä¿ãªããããã¼ã«ã«ãã¹ãã® 3000 çªãã 3003 çªãã¼ãã§åãã¦ãã Rails ã¢ããªã±ã¼ã·ã§ã³ã«ãªã¯ã¨ã¹ããä¸ç¶ãã¦ãããmaintenance.html
ãåå¨ããªãç¶æ
ï¼ã¤ã¾ããæ®éã®ç¶æ
ï¼ã§ããã°ããã¡ãã®ä»çµã¿ãåãã¦ããµã¤ã訪åè
ã« Rails ã¢ããªã±ã¼ã·ã§ã³ãè¦ããã
ã§ã¯ãdeploy:web:disable
ã¿ã¹ã¯ãå®è¡ãã¦ã¿ããã
% cap deploy:web:disable * executing `deploy:web:disable' servers: ["alpha.oiax.jp"] ** sftp upload #<StringIO:0xb7855b6c> -> /var/rails/ballad/shared/system/maintenance.html [alpha.oiax.jp] /var/rails/ballad/shared/system/maintenance.html [alpha.oiax.jp] done * sftp upload complete
ãã©ã¦ã¶ã§ http://ballad.example.com/ï¼å®éã«ã¯åå¨ãã¾ããï¼ãéãã¨ã確ãã«ã¡ã³ããã³ã¹ãã¼ã¸ã表示ãããã
ç»é¢ã«è¡¨ç¤ºãããã¡ãã»ã¼ã¸ã«ã¯ sftp
ã¨ããæåãè¦ãããã¨ãããã¨ã¯ãã¡ã³ããã³ã¹ãã¼ã¸ã¯ãã¼ã«ã«ãã¹ãï¼ããªãã®ãã½ã³ã³ï¼ã§ä½ããã¦ãªã¢ã¼ããã¹ãã«éãè¾¼ã¾ããããã ã
次ã«ãdeploy:web:enable
ã¿ã¹ã¯ã
% cap deploy:web:enable * executing `deploy:web:enable' * executing "rm /var/rails/ballad/shared/system/maintenance.html" servers: ["alpha.oiax.jp"] [alpha.oiax.jp] executing command command finished
ããå ã«æ»ã£ãï¼
ãã§ããããã§ããã