SERVER_PROTOCOL: <%= Settings.server_protocol.to_json %>,
SERVER_URL: <%= Settings.server_url.to_json %>,
API_VERSION: <%= Settings.api_version.to_json %>,
- STATUS: <%= STATUS.to_json %>,
+ STATUS: <%= Settings.status.to_json %>,
MAX_NOTE_REQUEST_AREA: <%= Settings.max_note_request_area.to_json %>,
OVERPASS_URL: <%= Settings.overpass_url.to_json %>,
NOMINATIM_URL: <%= Settings.nominatim_url.to_json %>,
end
def offline_redirect
- redirect_to :action => :offline if STATUS == :gpx_offline
+ redirect_to :action => :offline if Settings.status == "gpx_offline"
end
end
end
end
def check_database_readable(need_api = false)
- if STATUS == :database_offline || (need_api && STATUS == :api_offline)
+ if Settings.status == "database_offline" || (need_api && Settings.status == "api_offline")
if request.xhr?
report_error "Database offline for maintenance", :service_unavailable
else
end
def check_database_writable(need_api = false)
- if STATUS == :database_offline || STATUS == :database_readonly ||
- (need_api && (STATUS == :api_offline || STATUS == :api_readonly))
+ if Settings.status == "database_offline" || Settings.status == "database_readonly" ||
+ (need_api && (Settings.status == "api_offline" || Settings.status == "api_readonly"))
if request.xhr?
report_error "Database offline for maintenance", :service_unavailable
else
end
def database_status
- if STATUS == :database_offline
+ if Settings.status == "database_offline"
:offline
- elsif STATUS == :database_readonly
+ elsif Settings.status == "database_readonly"
:readonly
else
:online
def api_status
status = database_status
if status == :online
- if STATUS == :api_offline
+ if Settings.status == "api_offline"
status = :offline
- elsif STATUS == :api_readonly
+ elsif Settings.status == "api_readonly"
status = :readonly
end
end
def gpx_status
status = database_status
- status = :offline if status == :online && STATUS == :gpx_offline
+ status = :offline if status == :online && Settings.status == "gpx_offline"
status
end
:style_src => %w['unsafe-inline']
)
- if STATUS == :database_offline || STATUS == :api_offline
+ if Settings.status == "database_offline" || Settings.status == "api_offline"
flash.now[:warning] = t("layouts.osm_offline")
- elsif STATUS == :database_readonly || STATUS == :api_readonly
+ elsif Settings.status == "database_readonly" || Settings.status == "api_readonly"
flash.now[:warning] = t("layouts.osm_read_only")
end
authorize_resource :class => false
def index
- session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"]) unless STATUS == :database_readonly || STATUS == :database_offline
+ session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"]) unless Settings.status == "database_readonly" || Settings.status == "database_offline"
end
def permalink
end
def offline_warning
- flash.now[:warning] = t "traces.offline_warning.message" if STATUS == :gpx_offline
+ flash.now[:warning] = t "traces.offline_warning.message" if Settings.status == "gpx_offline"
end
def offline_redirect
- redirect_to :action => :offline if STATUS == :gpx_offline
+ redirect_to :action => :offline if Settings.status == "gpx_offline"
end
def default_visibility
<% content_for :content do %>
- <% if STATUS == :database_offline or STATUS == :api_offline %>
+ <% if Settings.status == "database_offline" or Settings.status == "api_offline" %>
<p><%= t 'layouts.osm_offline' %></p>
- <% elsif STATUS == :database_readonly or STATUS == :api_readonly %>
+ <% elsif Settings.status == "database_readonly" or Settings.status == "api_readonly" %>
<p><%= t 'layouts.osm_read_only' %></p>
<% elsif !current_user.data_public? %>
<p><%= t '.not_public' %></p>
-<% if STATUS == :database_offline %>
+<% if Settings.status == "database_offline" %>
<p><%= t 'layouts.osm_offline' %>
</p>
<% else %>
<tr>
<% cl = cycle('table0', 'table1') %>
<td class="<%= cl %>">
- <% if STATUS != :gpx_offline %>
+ <% if Settings.status != "gpx_offline" %>
<% if trace.inserted %>
<a href="<%= url_for :controller => 'traces', :action => 'show', :id => trace.id, :display_name => trace.user.display_name %>"><img src="<%= url_for :controller => 'traces', :action => 'icon', :id => trace.id, :display_name => trace.user.display_name %>" border="0" alt="" /></a>
<% else %>
<h2><%= t '.heading', :name => h(@trace.name) %></h2>
<% end %>
-<% if STATUS != :gpx_offline %>
+<% if Settings.status != "gpx_offline" %>
<% if @trace.inserted %>
<img src="<%= url_for :controller => 'traces', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
<% else %>
end
# rubocop:enable Rails/Output, Rails/Exit
-# Set the STATUS constant from the environment, if it matches a recognized value
-ALLOWED_STATUS = [
- :online, # online and operating normally
- :api_readonly, # site online but API in read-only mode
- :api_offline, # site online but API offline
- :database_readonly, # database and site in read-only mode
- :database_offline, # database offline with site in emergency mode
- :gpx_offline # gpx storage offline
-].freeze
-
-status = if ENV["STATUS"] && ALLOWED_STATUS.include?(ENV["STATUS"].to_sym)
- ENV["STATUS"].to_sym
- else
- :online
- end
-Object.const_set("STATUS", status)
-
-if STATUS == :database_offline
+if ENV["OPENSTREETMAP_STATUS"] == "database_offline"
require "active_model/railtie"
require "active_job/railtie"
require "active_storage/engine"
# This defaults to true from rails 5.0 but our code doesn't comply
# with it at all so we turn it off
- config.active_record.belongs_to_required_by_default = false unless STATUS == :database_offline
+ config.active_record.belongs_to_required_by_default = false unless Settings.status == "database_offline"
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
- config.active_record.schema_format = :sql unless STATUS == :database_offline
+ config.active_record.schema_format = :sql unless Settings.status == "database_offline"
# Don't eager load models when the database is offline
- config.paths["app/models"].skip_eager_load! if STATUS == :database_offline
+ config.paths["app/models"].skip_eager_load! if Settings.status == "database_offline"
# Use memcached for caching if required
config.cache_store = :mem_cache_store, Settings.memcache_servers, { :namespace => "rails:cache" } if Settings.key?(:memcache_servers)
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
- config.active_record.migration_error = :page_load unless STATUS == :database_offline
+ config.active_record.migration_error = :page_load unless Settings.status == "database_offline"
# Highlight code that triggered database queries in logs.
- config.active_record.verbose_query_logs = true unless STATUS == :database_offline
+ config.active_record.verbose_query_logs = true unless Settings.status == "database_offline"
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
end
# Do not dump schema after migrations.
- config.active_record.dump_schema_after_migration = false unless STATUS == :database_offline
+ config.active_record.dump_schema_after_migration = false unless Settings.status == "database_offline"
# Enable autoloading of dependencies.
config.enable_dependency_loading = true
+# Allowed status values
+ALLOWED_STATUS ||= [
+ "online", # online and operating normally
+ "api_readonly", # site online but API in read-only mode
+ "api_offline", # site online but API offline
+ "database_readonly", # database and site in read-only mode
+ "database_offline", # database offline with site in emergency mode
+ "gpx_offline" # gpx storage offline
+].freeze
+
Config.setup do |config|
# Name of the constant exposing loaded settings
config.const_name = "Settings"
# Load environment variables from the `ENV` object and override any settings defined in files.
#
- # config.use_env = false
+ config.use_env = true
# Define ENV variable prefix deciding which variables to load into config.
#
- # config.env_prefix = 'Settings'
+ config.env_prefix = "OPENSTREETMAP"
# What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
# with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
# using dots in variable names might not be allowed (eg. Bash).
#
- # config.env_separator = '.'
+ config.env_separator = "_"
# Ability to process variables names:
# * nil - no change
# * :downcase - convert to lower case
#
- # config.env_converter = :downcase
+ config.env_converter = :downcase
# Parse numeric values as integers instead of strings.
#
required(:max_number_of_way_nodes).filled(:int?)
required(:api_timeout).filled(:int?)
required(:imagery_blacklist).maybe(:array?)
+ required(:status).filled(:str?, :included_in? => ALLOWED_STATUS)
end
end
# API version
api_version: "0.6"
# Application status - possible values are:
-# :online - online and operating normally
-# :api_readonly - site online but API in read-only mode
-# :api_offline - site online but API offline
-# :database_readonly - database and site in read-only mode
-# :database_offline - database offline with site in emergency mode
-# :gpx_offline - gpx storage offline
-status: :online
+# online - online and operating normally
+# api_readonly - site online but API in read-only mode
+# api_offline - site online but API offline
+# database_readonly - database and site in read-only mode
+# database_offline - database offline with site in emergency mode
+# gpx_offline - gpx storage offline
+status: "online"
# The maximum area you're allowed to request, in square degrees
max_request_area: 0.25
# Number of GPS trace/trackpoints returned per-page