« Rails で mysql の ENUM カラムを使用する | メイン | ActiveRecordでデフォルトの並び順を指定 »

Capistrano で簡単にメンテナンス画面表示(2)

[rails] [capistrano] [deploy]

http://i-am.web777.net/2007/01/capistrano.html

上記エントリーの続き

メンテナンス画面は、カレントディレクトリに maintenance.rhtml がある場合はこちらがテンプレートとして使用される。

単純に RAILS_ROOT に maintenance.rhtml を設置してもよいが、あまり綺麗じゃないので、少し disable_web タスクを少し変更してみる。

テンプレートを config/templates/maintenance.rhtml に配置して config/deploy.rb に以下のように記述。


task :disable_web do
  # Get the current path
  dir = `pwd`.chomp

  # Copy the template to the current path (this is where 'render' looks)
  `cp #{dir}/config/templates/maintenance.rhtml #{dir}/maintenance.rhtml`

  # Read in file with replacements
  maintenance = render("maintenance", :deadline => ENV['UNTIL'], :reason => ENV['REASON'])

  # Copy to the server
  put maintenance, "#{shared_path}/system/maintenance.html", :mode => 0644

  # Remove local copy
  `rm #{dir}/maintenance.rhtml`

  # Just in case something goes wrong, clean up
  on_rollback do
    `rm #{dir}/maintenance.rhtml`
    delete "#{shared_path}/system/maintenance.html"
  end
end

これでOK。

参考サイト

トラックバック

このエントリーのトラックバックURL:
http://i-am.web777.net/mt/mt-tb.cgi/35

コメントを投稿