This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ru
More file actions
79 lines (62 loc) · 2.11 KB
/
Copy pathconfig.ru
File metadata and controls
79 lines (62 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#\ -s puma
# encoding: UTF-8
require 'pp'
require 'json'
require 'logger'
require 'rack'
$:.unshift File.dirname(__FILE__)
require 'simple_tiles'
$stdout.sync = true
#
# Startup
#
environment = ENV['RACK_ENV'] || 'development'
config_file = if environment == 'development' then File.join(Dir.pwd, 'simple_tiles.cfg') else '/etc/simple_tiles.cfg' end
layer_config_file = if environment == 'development' then File.join(Dir.pwd, 'simple_tiles_layers.cfg') else '/etc/simple_tiles_layers.cfg' end
configuration = {
port: 3000,
hostname: '127.0.0.1',
logfile: 'console',
path_prefix: ''
}
layer_configuration = {
layers: []
}
begin
configuration.merge!(JSON.parse(File.read(config_file), symbolize_names: true))
rescue Exception => e
pp e
puts "Invalid configuration file #{config_file}"
exit(1)
end
begin
layer_configuration.merge!(JSON.parse(File.read(layer_config_file), symbolize_names: true))
rescue Exception => e
pp e
puts "Invalid layer configuration file #{config_file}"
exit(1)
end
puts "[#{Time.now.strftime('%d/%b/%Y:%H:%M:%S %z')}] SimpleTiles server listening on #{configuration[:hostname]}:#{configuration[:port]} in #{environment} mode, log to #{configuration[:logfile]}"
app_logger = nil
if configuration[:logfile] == 'null' or configuration[:logfile] == '/dev/null'
puts "[#{Time.now.strftime('%d/%b/%Y:%H:%M:%S %z')}] Discarding access logs"
app_logger = Logger.new('/dev/null')
elsif configuration[:logfile] == 'console'
puts "[#{Time.now.strftime('%d/%b/%Y:%H:%M:%S %z')}] Logging to STDOUT"
app_logger = STDOUT
else
puts "[#{Time.now.strftime('%d/%b/%Y:%H:%M:%S %z')}] Redefining app_logger..."
app_logger = Logger.new(File.expand_path(configuration[:logfile]), 'daily')
end
SimpleTilesAdapter.setup_db(layer_configuration)
use Rack::SimpleTilesLogger, app_logger if app_logger
puts "[#{Time.now.strftime('%d/%b/%Y:%H:%M:%S %z')}] Setup done, loading maps..."
map configuration[:path_prefix] do
run SimpleTilesAdapter.new
end
map '/statistics' do
run StatisticsAdapter.new
end
map '/statistics.json' do
run JSONStatisticsAdapter.new
end