bullion 0.12.0 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +46 -11
- data/Rakefile +15 -7
- data/config/puma.rb +36 -0
- data/config.ru +5 -1
- data/db/migrate/20261102000000_add_created_at_index_to_nonces.rb +8 -0
- data/db/schema.rb +2 -1
- data/lib/bullion/acme/error.rb +35 -9
- data/lib/bullion/helpers/acme.rb +180 -14
- data/lib/bullion/helpers/ssl.rb +32 -5
- data/lib/bullion/models/authorization.rb +16 -0
- data/lib/bullion/models/certificate.rb +6 -1
- data/lib/bullion/models/challenge.rb +6 -0
- data/lib/bullion/models/nonce.rb +43 -4
- data/lib/bullion/models/order.rb +13 -0
- data/lib/bullion/models/order_csr.rb +5 -1
- data/lib/bullion/service.rb +67 -6
- data/lib/bullion/services/ca.rb +55 -36
- data/lib/bullion/version.rb +1 -1
- data/lib/bullion.rb +79 -16
- metadata +40 -21
- data/Itsi.rb +0 -123
data/lib/bullion.rb
CHANGED
|
@@ -34,9 +34,22 @@ module Bullion
|
|
|
34
34
|
LOGGER = Logger.new($stdout)
|
|
35
35
|
LOGGER.level = ENV.fetch("LOG_LEVEL", :warn)
|
|
36
36
|
|
|
37
|
+
# Environments in which Bullion is allowed to fall back to a well-known,
|
|
38
|
+
# development-only passphrase for the CA private key. Every other environment
|
|
39
|
+
# (production, or an unset RACK_ENV) must supply CA_SECRET explicitly.
|
|
40
|
+
DEV_OR_TEST_ENVIRONMENTS = %w[development test].freeze
|
|
41
|
+
|
|
42
|
+
# Development/test-only fallback passphrase for the CA private key. This value is
|
|
43
|
+
# deliberately well-known: it exists so that local development and the test suite
|
|
44
|
+
# can boot without extra setup. It is never used when RACK_ENV is something other
|
|
45
|
+
# than "development" or "test".
|
|
46
|
+
DEV_ONLY_SECRET = "SomeS3cret"
|
|
47
|
+
|
|
37
48
|
setting :ca, reader: true do
|
|
38
49
|
setting :dir, default: "tmp", constructor: -> { File.expand_path(it) }
|
|
39
|
-
|
|
50
|
+
# The passphrase used to decrypt the CA private key. There is deliberately no
|
|
51
|
+
# default here; see {resolve_ca_secret} and {validate_config!}.
|
|
52
|
+
setting :secret
|
|
40
53
|
setting(
|
|
41
54
|
:key_path,
|
|
42
55
|
default: "tls.key",
|
|
@@ -71,11 +84,23 @@ module Bullion
|
|
|
71
84
|
MetricsRegistry = Prometheus::Client.registry
|
|
72
85
|
|
|
73
86
|
def self.ca_key
|
|
74
|
-
@ca_key ||=
|
|
75
|
-
|
|
87
|
+
@ca_key ||= load_ca_key
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Loads the CA private key, decrypting it with the configured passphrase
|
|
91
|
+
# @raise [ConfigError] if the key cannot be decrypted with the configured passphrase
|
|
92
|
+
# @return [OpenSSL::PKey::RSA, OpenSSL::PKey::EC] the decrypted CA private key
|
|
93
|
+
def self.load_ca_key
|
|
94
|
+
pem = File.read(config.ca.key_path)
|
|
95
|
+
begin
|
|
96
|
+
OpenSSL::PKey::RSA.new(pem, config.ca.secret)
|
|
76
97
|
rescue OpenSSL::PKey::RSAError
|
|
77
|
-
OpenSSL::PKey::EC.new(
|
|
98
|
+
OpenSSL::PKey::EC.new(pem, config.ca.secret)
|
|
78
99
|
end
|
|
100
|
+
rescue OpenSSL::PKey::ECError => e
|
|
101
|
+
raise ConfigError,
|
|
102
|
+
"Unable to decrypt the CA private key at #{config.ca.key_path}: check that CA_SECRET " \
|
|
103
|
+
"matches the passphrase used to encrypt the key (#{e.message})"
|
|
79
104
|
end
|
|
80
105
|
|
|
81
106
|
def self.ca_cert_file
|
|
@@ -94,10 +119,39 @@ module Bullion
|
|
|
94
119
|
true
|
|
95
120
|
end
|
|
96
121
|
|
|
122
|
+
# Resolves the passphrase used to decrypt the CA private key.
|
|
123
|
+
#
|
|
124
|
+
# An explicitly configured passphrase always wins. When none is given, a
|
|
125
|
+
# development/test-only fallback is used so that local development and the test
|
|
126
|
+
# suite can boot without extra setup. In every other environment (production, or
|
|
127
|
+
# an unset RACK_ENV) this resolves to +nil+ so that {.validate_config!} fails
|
|
128
|
+
# closed instead of silently using a well-known passphrase.
|
|
129
|
+
#
|
|
130
|
+
# @param secret [String, nil] the configured CA_SECRET value, if any
|
|
131
|
+
# @param rack_env [String, nil] the RACK_ENV value, if any
|
|
132
|
+
# @return [String, nil] the passphrase to use, or +nil+ when one is required
|
|
133
|
+
def self.resolve_ca_secret(secret, rack_env = ENV.fetch("RACK_ENV", nil))
|
|
134
|
+
return secret unless secret.nil? || secret.to_s.strip.empty?
|
|
135
|
+
|
|
136
|
+
DEV_OR_TEST_ENVIRONMENTS.include?(rack_env) ? DEV_ONLY_SECRET : nil
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Ensures the passphrase used to decrypt the CA private key is present
|
|
140
|
+
# @raise [ConfigError] if the passphrase is missing, blank, or not a String
|
|
141
|
+
# @return [void]
|
|
142
|
+
def self.validate_ca_secret!
|
|
143
|
+
secret = config.ca.secret
|
|
144
|
+
return if secret.is_a?(String) && !secret.strip.empty?
|
|
145
|
+
|
|
146
|
+
raise ConfigError,
|
|
147
|
+
"Missing or invalid CA_SECRET: set the CA_SECRET environment variable to the " \
|
|
148
|
+
"passphrase that decrypts the CA private key at #{config.ca.key_path}"
|
|
149
|
+
end
|
|
150
|
+
|
|
97
151
|
# Ensures configuration settings are valid
|
|
98
152
|
# @see https://support.apple.com/en-us/HT211025
|
|
99
153
|
def self.validate_config! # rubocop:disable Metrics/AbcSize
|
|
100
|
-
|
|
154
|
+
validate_ca_secret!
|
|
101
155
|
|
|
102
156
|
unless File.readable?(config.ca.key_path)
|
|
103
157
|
raise ConfigError,
|
|
@@ -130,8 +184,18 @@ Bullion.configure do |config|
|
|
|
130
184
|
db_url = ENV.fetch("DATABASE_URL", nil)
|
|
131
185
|
nameservers = ENV.fetch("DNS01_NAMESERVERS", nil)
|
|
132
186
|
|
|
187
|
+
# The CA passphrase has no default outside of development and test environments;
|
|
188
|
+
# resolve it here so that an unset CA_SECRET fails closed at boot.
|
|
189
|
+
resolved_secret = Bullion.resolve_ca_secret(ca_secret)
|
|
190
|
+
if resolved_secret == Bullion::DEV_ONLY_SECRET && ca_secret.to_s.strip.empty?
|
|
191
|
+
Bullion::LOGGER.warn(
|
|
192
|
+
"CA_SECRET is not set; using the well-known development-only CA passphrase. Set " \
|
|
193
|
+
"CA_SECRET to a strong passphrase for any non-development deployment."
|
|
194
|
+
)
|
|
195
|
+
end
|
|
196
|
+
|
|
133
197
|
config.ca.dir = ca_dir if ca_dir
|
|
134
|
-
config.ca.secret =
|
|
198
|
+
config.ca.secret = resolved_secret
|
|
135
199
|
config.ca.key_path = ca_key_path if ca_key_path
|
|
136
200
|
config.ca.cert_path = ca_cert_path if ca_cert_path
|
|
137
201
|
config.ca.domains = ca_domains if ca_domains
|
|
@@ -140,16 +204,15 @@ Bullion.configure do |config|
|
|
|
140
204
|
config.nameservers = nameservers if nameservers
|
|
141
205
|
end
|
|
142
206
|
|
|
143
|
-
#
|
|
144
|
-
# share an ActiveSupport execution context by default.
|
|
145
|
-
# database connection per execution context, so without
|
|
146
|
-
# concurrent request fiber on a thread shares (and races
|
|
147
|
-
# connection. Trilogy detects this and raises
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
# opt-out.
|
|
207
|
+
# Puma serves each request inside its own Fiber (via `fiber_per_request`), but
|
|
208
|
+
# all fibers on a thread share an ActiveSupport execution context by default.
|
|
209
|
+
# ActiveRecord leases a database connection per execution context, so without
|
|
210
|
+
# fiber isolation every concurrent request fiber on a thread shares (and races
|
|
211
|
+
# on) the same connection. Trilogy detects this and raises
|
|
212
|
+
# Trilogy::SynchronizationError. Opt into fiber isolation, honoring Puma's
|
|
213
|
+
# fiber_per_request opt-out.
|
|
151
214
|
# @see https://github.com/jgnagy/bullion/issues/116
|
|
152
|
-
unless ENV["
|
|
215
|
+
unless ENV["PUMA_DISABLE_AS_AUTO_FIBER_ISOLATION_LEVEL"]
|
|
153
216
|
ActiveSupport::IsolatedExecutionState.isolation_level = :fiber
|
|
154
217
|
end
|
|
155
218
|
|
|
@@ -167,7 +230,7 @@ require "bullion/challenge_client"
|
|
|
167
230
|
require "bullion/challenge_clients/dns"
|
|
168
231
|
require "bullion/challenge_clients/http"
|
|
169
232
|
|
|
170
|
-
if
|
|
233
|
+
if Bullion::DEV_OR_TEST_ENVIRONMENTS.include?(ENV["RACK_ENV"])
|
|
171
234
|
require "bullion/rspec/challenge_clients/dns"
|
|
172
235
|
require "bullion/rspec/challenge_clients/http"
|
|
173
236
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bullion
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.12.
|
|
4
|
+
version: 0.12.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jonathan Gnagy
|
|
@@ -52,40 +52,46 @@ dependencies:
|
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '0.21'
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
|
-
name:
|
|
55
|
+
name: puma
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
|
58
58
|
- - "~>"
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: '0
|
|
60
|
+
version: '8.0'
|
|
61
61
|
type: :runtime
|
|
62
62
|
prerelease: false
|
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements:
|
|
65
65
|
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: '0
|
|
67
|
+
version: '8.0'
|
|
68
68
|
- !ruby/object:Gem::Dependency
|
|
69
69
|
name: json
|
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
|
71
71
|
requirements:
|
|
72
|
-
- - "
|
|
72
|
+
- - ">="
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
|
-
version:
|
|
74
|
+
version: 2.21.2
|
|
75
|
+
- - "<"
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '3.0'
|
|
75
78
|
type: :runtime
|
|
76
79
|
prerelease: false
|
|
77
80
|
version_requirements: !ruby/object:Gem::Requirement
|
|
78
81
|
requirements:
|
|
79
|
-
- - "
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: 2.21.2
|
|
85
|
+
- - "<"
|
|
80
86
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: '
|
|
87
|
+
version: '3.0'
|
|
82
88
|
- !ruby/object:Gem::Dependency
|
|
83
89
|
name: jwt
|
|
84
90
|
requirement: !ruby/object:Gem::Requirement
|
|
85
91
|
requirements:
|
|
86
92
|
- - ">="
|
|
87
93
|
- !ruby/object:Gem::Version
|
|
88
|
-
version:
|
|
94
|
+
version: 3.2.0
|
|
89
95
|
- - "<"
|
|
90
96
|
- !ruby/object:Gem::Version
|
|
91
97
|
version: '4.0'
|
|
@@ -95,7 +101,7 @@ dependencies:
|
|
|
95
101
|
requirements:
|
|
96
102
|
- - ">="
|
|
97
103
|
- !ruby/object:Gem::Version
|
|
98
|
-
version:
|
|
104
|
+
version: 3.2.0
|
|
99
105
|
- - "<"
|
|
100
106
|
- !ruby/object:Gem::Version
|
|
101
107
|
version: '4.0'
|
|
@@ -103,16 +109,22 @@ dependencies:
|
|
|
103
109
|
name: jwt-eddsa
|
|
104
110
|
requirement: !ruby/object:Gem::Requirement
|
|
105
111
|
requirements:
|
|
106
|
-
- - "
|
|
112
|
+
- - ">="
|
|
107
113
|
- !ruby/object:Gem::Version
|
|
108
114
|
version: '0.9'
|
|
115
|
+
- - "<"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '2.0'
|
|
109
118
|
type: :runtime
|
|
110
119
|
prerelease: false
|
|
111
120
|
version_requirements: !ruby/object:Gem::Requirement
|
|
112
121
|
requirements:
|
|
113
|
-
- - "
|
|
122
|
+
- - ">="
|
|
114
123
|
- !ruby/object:Gem::Version
|
|
115
124
|
version: '0.9'
|
|
125
|
+
- - "<"
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '2.0'
|
|
116
128
|
- !ruby/object:Gem::Dependency
|
|
117
129
|
name: openssl
|
|
118
130
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -137,16 +149,22 @@ dependencies:
|
|
|
137
149
|
name: prometheus-client
|
|
138
150
|
requirement: !ruby/object:Gem::Requirement
|
|
139
151
|
requirements:
|
|
140
|
-
- - "
|
|
152
|
+
- - ">="
|
|
141
153
|
- !ruby/object:Gem::Version
|
|
142
154
|
version: '4.2'
|
|
155
|
+
- - "<"
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: '6.0'
|
|
143
158
|
type: :runtime
|
|
144
159
|
prerelease: false
|
|
145
160
|
version_requirements: !ruby/object:Gem::Requirement
|
|
146
161
|
requirements:
|
|
147
|
-
- - "
|
|
162
|
+
- - ">="
|
|
148
163
|
- !ruby/object:Gem::Version
|
|
149
164
|
version: '4.2'
|
|
165
|
+
- - "<"
|
|
166
|
+
- !ruby/object:Gem::Version
|
|
167
|
+
version: '6.0'
|
|
150
168
|
- !ruby/object:Gem::Dependency
|
|
151
169
|
name: sinatra
|
|
152
170
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -221,14 +239,14 @@ dependencies:
|
|
|
221
239
|
requirements:
|
|
222
240
|
- - "~>"
|
|
223
241
|
- !ruby/object:Gem::Version
|
|
224
|
-
version:
|
|
242
|
+
version: 2.13.2
|
|
225
243
|
type: :runtime
|
|
226
244
|
prerelease: false
|
|
227
245
|
version_requirements: !ruby/object:Gem::Requirement
|
|
228
246
|
requirements:
|
|
229
247
|
- - "~>"
|
|
230
248
|
- !ruby/object:Gem::Version
|
|
231
|
-
version:
|
|
249
|
+
version: 2.13.2
|
|
232
250
|
- !ruby/object:Gem::Dependency
|
|
233
251
|
name: acme-client
|
|
234
252
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -373,28 +391,28 @@ dependencies:
|
|
|
373
391
|
requirements:
|
|
374
392
|
- - "~>"
|
|
375
393
|
- !ruby/object:Gem::Version
|
|
376
|
-
version: '
|
|
394
|
+
version: '1.3'
|
|
377
395
|
type: :development
|
|
378
396
|
prerelease: false
|
|
379
397
|
version_requirements: !ruby/object:Gem::Requirement
|
|
380
398
|
requirements:
|
|
381
399
|
- - "~>"
|
|
382
400
|
- !ruby/object:Gem::Version
|
|
383
|
-
version: '
|
|
401
|
+
version: '1.3'
|
|
384
402
|
- !ruby/object:Gem::Dependency
|
|
385
403
|
name: simplecov-cobertura
|
|
386
404
|
requirement: !ruby/object:Gem::Requirement
|
|
387
405
|
requirements:
|
|
388
406
|
- - "~>"
|
|
389
407
|
- !ruby/object:Gem::Version
|
|
390
|
-
version: '
|
|
408
|
+
version: '4.0'
|
|
391
409
|
type: :development
|
|
392
410
|
prerelease: false
|
|
393
411
|
version_requirements: !ruby/object:Gem::Requirement
|
|
394
412
|
requirements:
|
|
395
413
|
- - "~>"
|
|
396
414
|
- !ruby/object:Gem::Version
|
|
397
|
-
version: '
|
|
415
|
+
version: '4.0'
|
|
398
416
|
- !ruby/object:Gem::Dependency
|
|
399
417
|
name: solargraph
|
|
400
418
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -431,13 +449,13 @@ extra_rdoc_files: []
|
|
|
431
449
|
files:
|
|
432
450
|
- ".ruby-version"
|
|
433
451
|
- CHANGELOG.md
|
|
434
|
-
- Itsi.rb
|
|
435
452
|
- LICENSE.txt
|
|
436
453
|
- README.md
|
|
437
454
|
- Rakefile
|
|
438
455
|
- bin/console
|
|
439
456
|
- bin/setup
|
|
440
457
|
- config.ru
|
|
458
|
+
- config/puma.rb
|
|
441
459
|
- db/migrate/20210104000000_create_accounts.rb
|
|
442
460
|
- db/migrate/20210104060422_create_certificates.rb
|
|
443
461
|
- db/migrate/20210105060406_create_orders.rb
|
|
@@ -446,6 +464,7 @@ files:
|
|
|
446
464
|
- db/migrate/20210106060335_create_nonces.rb
|
|
447
465
|
- db/migrate/20250823073342_add_public_key_hash_to_accounts.rb
|
|
448
466
|
- db/migrate/20260716000000_add_revocation_to_certificates.rb
|
|
467
|
+
- db/migrate/20261102000000_add_created_at_index_to_nonces.rb
|
|
449
468
|
- db/schema.rb
|
|
450
469
|
- lib/bullion.rb
|
|
451
470
|
- lib/bullion/acme/error.rb
|
data/Itsi.rb
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# This is the default Itsi configuration file, installed when you run `itsi init`
|
|
4
|
-
# It contains a sane starting point for configuring your Itsi server.
|
|
5
|
-
# You can use this file in both development and production environments.
|
|
6
|
-
# Most of the options in this file can be overridden by command line options.
|
|
7
|
-
# Check out itsi -h to learn more about the command line options available to you.
|
|
8
|
-
|
|
9
|
-
env = ENV.fetch("APP_ENV") { ENV.fetch("RACK_ENV", "development") }
|
|
10
|
-
|
|
11
|
-
# Number of worker processes to spawn
|
|
12
|
-
# If more than 1, Itsi will be booted in Cluster mode
|
|
13
|
-
workers ENV["WORKERS"]&.to_i || (env == "development" ? 1 : nil)
|
|
14
|
-
|
|
15
|
-
# Number of threads to spawn per worker process
|
|
16
|
-
# For pure CPU bound applicationss, you'll get the best results keeping this number low
|
|
17
|
-
# Setting a value of 1 is great for superficial benchmarks, but in reality
|
|
18
|
-
# it's better to set this a bit higher to allow expensive requests to get overtaken and minimize head-of-line blocking
|
|
19
|
-
threads ENV.fetch("THREADS", 3).to_i
|
|
20
|
-
|
|
21
|
-
# If your application is IO bound (e.g. performing a lot of proxied HTTP requests, or heavy queries etc)
|
|
22
|
-
# you can see *substantial* benefits from enabling this option.
|
|
23
|
-
# To set this option, pass a string, not a class (as we will not have loaded the class yet)
|
|
24
|
-
# E.g.
|
|
25
|
-
# `fiber_scheduler "Itsi::Scheduler"` - The default fast and light-weight scheduler that comes with Itsi
|
|
26
|
-
# `fiber_scheduler "Async::Scheduler"` - Bring your own scheduler!
|
|
27
|
-
fiber_scheduler "Itsi::Scheduler"
|
|
28
|
-
|
|
29
|
-
# If you bind to https, without specifying a certificate, Itsi will use a self-signed certificate.
|
|
30
|
-
# The self-signed certificate will use a CA generated for your
|
|
31
|
-
# host and stored inside `ITSI_LOCAL_CA_DIR` (Defaults to ~/.itsi)
|
|
32
|
-
# bind "https://0.0.0.0:3000"
|
|
33
|
-
# bind "https://0.0.0.0:3000?domains=dev.itsi.fyi"
|
|
34
|
-
#
|
|
35
|
-
# If you want to use let's encrypt to generate you a real certificate you
|
|
36
|
-
# and pass cert=acme and an acme_email address to generate one.
|
|
37
|
-
# bind "https://itsi.fyi?cert=acme&acme_email=admin@itsi.fyi"
|
|
38
|
-
# You can generate certificates for multiple domains at once, by passing a comma-separated list of domains
|
|
39
|
-
# bind "https://0.0.0.0?domains=foo.itsi.fyi,bar.itsi.fyi&cert=acme&acme_email=admin@itsi.fyi"
|
|
40
|
-
#
|
|
41
|
-
# If you already have a certificate you can specify it using the cert and key parameters
|
|
42
|
-
# bind "https://itsi.fyi?cert=/path/to/cert.pem&key=/path/to/key.pem"
|
|
43
|
-
#
|
|
44
|
-
# You can also bind to a unix socket or a tls unix socket. E.g.
|
|
45
|
-
# bind "unix:///tmp/itsi.sock"
|
|
46
|
-
# bind "tls:///tmp/itsi.secure.sock"
|
|
47
|
-
|
|
48
|
-
bind "http://0.0.0.0:#{ENV.fetch("BULLION_PORT", 9292)}"
|
|
49
|
-
|
|
50
|
-
# If you want to preload the application, set preload to true
|
|
51
|
-
# to load the entire rack-app defined in rack_file_name before forking.
|
|
52
|
-
# Alternatively, you can preload just a specific set of gems in a group in your gemfile,
|
|
53
|
-
# by providing the group name here.
|
|
54
|
-
# E.g.
|
|
55
|
-
#
|
|
56
|
-
# preload :preload # Load gems inside the preload group
|
|
57
|
-
# preload false # Don't preload.
|
|
58
|
-
#
|
|
59
|
-
# If you want to be able to perform zero-downtime deploys using a single itsi process,
|
|
60
|
-
# you should disable preloads, so that the application is loaded fresh each time a new worker boots
|
|
61
|
-
preload true
|
|
62
|
-
|
|
63
|
-
# Set the maximum memory limit for each worker process in bytes
|
|
64
|
-
# When this limit is reached, the worker will be gracefully restarted.
|
|
65
|
-
# Only one worker is restarted at a time to ensure we don't take down
|
|
66
|
-
# all of them at once, if they reach the threshold simultaneously.
|
|
67
|
-
worker_memory_limit ENV.fetch("WORKER_MEMORY_LIMIT") { 1024 * 1024 * 1024 } # Default to 1GB
|
|
68
|
-
|
|
69
|
-
# You can provide an optional block of code to run, when a worker hits its memory threshold
|
|
70
|
-
# (Use this to send yourself an alert,
|
|
71
|
-
# write metrics to disk etc. etc.)
|
|
72
|
-
after_memory_limit_reached do |pid|
|
|
73
|
-
puts "Worker #{pid} has reached its memory threshold and will restart"
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# Do clean up of any non-threadsafe resources before forking a new worker here.
|
|
77
|
-
before_fork {}
|
|
78
|
-
|
|
79
|
-
# Reinitialize any non-threadsafe resources after forking a new worker here.
|
|
80
|
-
after_fork {}
|
|
81
|
-
|
|
82
|
-
# Shutdown timeout
|
|
83
|
-
# Number of seconds to wait for workers to gracefully shutdown before killing them.
|
|
84
|
-
shutdown_timeout 5
|
|
85
|
-
|
|
86
|
-
# Set this to false for application environments that require rack.input to be a rewindable body
|
|
87
|
-
# (like Rails). For rack applications that can stream inputs, you can set this to true for a more
|
|
88
|
-
# memory-efficient approach.
|
|
89
|
-
stream_body false
|
|
90
|
-
|
|
91
|
-
# OOB GC responses threshold
|
|
92
|
-
# Specifies how frequently OOB gc should be triggered during periods where there is a gap in queued requests.
|
|
93
|
-
# Setting this too low can substantially worsen performance
|
|
94
|
-
oob_gc_responses_threshold 512
|
|
95
|
-
|
|
96
|
-
# Log level
|
|
97
|
-
# Set this to one of the following values: debug, info, warn, error, fatal
|
|
98
|
-
# Can also be set using the ITSI_LOG environment variable
|
|
99
|
-
log_level ENV.fetch("LOG_LEVEL", "warn").to_sym
|
|
100
|
-
|
|
101
|
-
# Log Format
|
|
102
|
-
# Set this to be either :plain or :json. If you leave it blank Itsi will try
|
|
103
|
-
# and auto-detect the format based on the TTY environment.
|
|
104
|
-
log_format :plain
|
|
105
|
-
# You can mount several Ruby apps as either
|
|
106
|
-
# 1. rackup files
|
|
107
|
-
# 2. inline rack apps
|
|
108
|
-
# 3. inline Ruby endpoints
|
|
109
|
-
#
|
|
110
|
-
# 1. rackup_file
|
|
111
|
-
rackup_file "./config.ru"
|
|
112
|
-
#
|
|
113
|
-
# 2. inline rack app
|
|
114
|
-
# require 'rack'
|
|
115
|
-
# run(Rack::Builder.app do
|
|
116
|
-
# use Rack::CommonLogger
|
|
117
|
-
# run ->(env) { [200, { 'content-type' => 'text/plain' }, ['OK']] }
|
|
118
|
-
# end)
|
|
119
|
-
#
|
|
120
|
-
# 3. Endpoints
|
|
121
|
-
# endpoint "/" do |req|
|
|
122
|
-
# req.ok "Hello from Itsi"
|
|
123
|
-
# end
|