タイマー指定でメンテナンスページ化したかった。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
以上です。