From: Tom Hughes Date: Thu, 20 Sep 2007 23:51:11 +0000 (+0000) Subject: Allow the API to be taken offline completely as well as being put into X-Git-Tag: live~8171 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/9c01c4cb639775f4f93f477546124247a33f80d2 Allow the API to be taken offline completely as well as being put into readonly mode, --- diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 3ba91fb8c..ea32acec8 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -2,7 +2,7 @@ class AmfController < ApplicationController require 'stringio' session :off - before_filter :check_availability + before_filter :check_write_availability # to log: # RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}") diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index b39cbddf5..3555260d2 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -1,6 +1,7 @@ class ApiController < ApplicationController session :off + before_filter :check_read_availability, :except => [:capabilities] after_filter :compress_output #COUNT is the number of map requests to allow before exiting and starting a new process diff --git a/app/controllers/application.rb b/app/controllers/application.rb index d22ed5c9f..acb2f9162 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -39,8 +39,16 @@ class ApplicationController < ActionController::Base end end - def check_availability - if API_READONLY + def check_read_availability + if API_STATUS == :offline + response.headers['Error'] = "Database offline for maintenance" + render :nothing => true, :status => :service_unavailable + return false + end + end + + def check_write_availability + if API_STATUS == :offline or API_STATUS == :readonly response.headers['Error'] = "Database offline for maintenance" render :nothing => true, :status => :service_unavailable return false diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 4e2a9b7f2..0a3897fe9 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -3,7 +3,8 @@ class NodeController < ApplicationController session :off before_filter :authorize, :only => [:create, :update, :delete] - before_filter :check_availability, :only => [:create, :update, :delete] + before_filter :check_write_availability, :only => [:create, :update, :delete] + before_filter :check_read_availability, :except => [:create, :update, :delete] after_filter :compress_output def create diff --git a/app/controllers/old_node_controller.rb b/app/controllers/old_node_controller.rb index 0337cb2cf..e27898336 100644 --- a/app/controllers/old_node_controller.rb +++ b/app/controllers/old_node_controller.rb @@ -2,6 +2,7 @@ class OldNodeController < ApplicationController require 'xml/libxml' session :off + before_filter :check_read_availability after_filter :compress_output def history diff --git a/app/controllers/old_segment_controller.rb b/app/controllers/old_segment_controller.rb index 2d48fb5b9..410760f2b 100644 --- a/app/controllers/old_segment_controller.rb +++ b/app/controllers/old_segment_controller.rb @@ -2,6 +2,7 @@ class OldSegmentController < ApplicationController require 'xml/libxml' session :off + before_filter :check_read_availability after_filter :compress_output def history diff --git a/app/controllers/old_way_controller.rb b/app/controllers/old_way_controller.rb index f10e0d2f0..e72c97a00 100644 --- a/app/controllers/old_way_controller.rb +++ b/app/controllers/old_way_controller.rb @@ -2,6 +2,7 @@ class OldWayController < ApplicationController require 'xml/libxml' session :off + before_filter :check_read_availability after_filter :compress_output def history diff --git a/app/controllers/segment_controller.rb b/app/controllers/segment_controller.rb index b99f7460f..b547d5cd1 100644 --- a/app/controllers/segment_controller.rb +++ b/app/controllers/segment_controller.rb @@ -3,7 +3,8 @@ class SegmentController < ApplicationController session :off before_filter :authorize, :only => [:create, :update, :delete] - before_filter :check_availability, :only => [:create, :update, :delete] + before_filter :check_write_availability, :only => [:create, :update, :delete] + before_filter :check_read_availability, :except => [:create, :update, :delete] after_filter :compress_output def create diff --git a/app/controllers/swf_controller.rb b/app/controllers/swf_controller.rb index 2200ab652..084a7d57a 100644 --- a/app/controllers/swf_controller.rb +++ b/app/controllers/swf_controller.rb @@ -1,6 +1,6 @@ class SwfController < ApplicationController session :off - before_filter :check_availability + before_filter :check_read_availability # to log: # RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}") diff --git a/app/controllers/way_controller.rb b/app/controllers/way_controller.rb index 935ff3a72..d569991af 100644 --- a/app/controllers/way_controller.rb +++ b/app/controllers/way_controller.rb @@ -3,7 +3,8 @@ class WayController < ApplicationController session :off before_filter :authorize, :only => [:create, :update, :delete] - before_filter :check_availability, :only => [:create, :update, :delete] + before_filter :check_write_availability, :only => [:create, :update, :delete] + before_filter :check_read_availability, :except => [:create, :update, :delete] after_filter :compress_output def create diff --git a/config/environment.rb b/config/environment.rb index 003a7b832..e58631901 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -77,8 +77,9 @@ end # inflect.uncountable %w( fish sheep ) # end -# Set to true to put the API in read-only mode -API_READONLY = false +# Set to :readonly to put the API in read-only mode or :offline to +# take it completely offline +API_STATUS = :online # Include your application configuration below SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'