LoginSignup
0
1

More than 5 years have passed since last update.

h2oでタイマーでリダイレクト(メンテナンスページ表示)

Last updated at Posted at 2019-02-13

タイマー指定でメンテナンスページ化したかった。Apacheのように。
Apacheのようなhtaccessはないが、service h2o reloadが許されるなら下記対応でOK

#h2o.cfg
     paths:
       "/":
         mruby.handler-file: /path/to/maintenance.rb
#maintenance.rb
class Maintenance
  # config                                                                                                                                                                                                          
  # format = %Y/%m/%d %H:%M:%S"                                                                                                                                                                                     
  START_DATETIME = "2019/02/13 00:00:00"
  END_DATETIME = "2019/02/13 18:47:00"
  MAINTENANCE_PATH = "/maintenance.html"

  def call(env)
    return [399, {}, [ ] ] if env["PATH_INFO"] == MAINTENANCE_PATH
    n = Time.new
    now = n.year.to_s + "/" + format('%02d', n.month) + "/" + format('%02d', n.day.to_s) + " " + format('%02d', n.hour.to_s) + ":" + format('%02d', n.min.to_s) + ":" + format('%02d', n.sec.to_s)
    if now >= START_DATETIME and now < END_DATETIME
      return [301, { 'Location' => MAINTENANCE_PATH }, [] ]
    else
      return [399, {}, [ ] ]
    end
  end
end

Maintenance.new

以上です。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1