synapse-nginx 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/synapse-nginx.rb +1 -1
- data/lib/synapse/config_generator/nginx.rb +20 -7
- data/spec/lib/synapse/nginx_spec.rb +65 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17104df4947dd6df10df533cfc41154754cc4d76
|
4
|
+
data.tar.gz: 559be673ff3f04e95884df1bdf85c6baae328c0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f73b1cc80e16696f4361425106dbba149e4f5a7afd38c03d1aaf91a43fb20e639064a6feb823ec8532729e998c0d4d9859a9851f998d12e59c069ad0fb1555a3
|
7
|
+
data.tar.gz: a8d8bca8f7cbdd7e877dac62e9a2e250006b57eb5c65f72f82f1a517b77b4ae21738d8ebd501091fecd6d75088585138d98f1f0794f3743cab23f2434ac7f25f
|
data/README.md
CHANGED
@@ -54,7 +54,8 @@ Required if `do_writes` is set.
|
|
54
54
|
You can control reloading with:
|
55
55
|
* `do_reloads`: whether or not Synapse will reload nginx automatically (default to `true`)
|
56
56
|
* `reload_command`: the command Synapse will run to reload NGINX. Required if `do_reloads` is set.
|
57
|
-
* `start_command`: the command Synapse will run to start NGINX the first time. Required if `do_reloads` is set.
|
57
|
+
* `start_command`: the command Synapse will run to start NGINX the first time. Required if `do_reloads` is set. You probably want this to check
|
58
|
+
if the existing NGINX is running (e.g. by sending the 0 signal to the master pid).
|
58
59
|
* `restart_interval`: number of seconds to wait between restarts of NGINX (default: 2)
|
59
60
|
* `restart_jitter`: percentage, expressed as a float, of jitter to multiply the `restart_interval` by when determining the next
|
60
61
|
restart time. Use this to help prevent storms when HAProxy restarts. (default: 0.0)
|
data/lib/synapse-nginx.rb
CHANGED
@@ -71,6 +71,11 @@ class Synapse::ConfigGenerator
|
|
71
71
|
def tick(watchers)
|
72
72
|
@time += 1
|
73
73
|
|
74
|
+
# Always ensure we try to start at least once
|
75
|
+
# Note that this should only trigger during error cases where for
|
76
|
+
# some reason Synapse could not start NGINX during the initial restart
|
77
|
+
start if opts['do_reloads'] && !@has_started
|
78
|
+
|
74
79
|
# We potentially have to restart if the restart was rate limited
|
75
80
|
# in the original call to update_config
|
76
81
|
restart if opts['do_reloads'] && @restart_required
|
@@ -289,6 +294,19 @@ class Synapse::ConfigGenerator
|
|
289
294
|
end
|
290
295
|
end
|
291
296
|
|
297
|
+
def start
|
298
|
+
log.info "synapse: attempting to run #{opts['start_command']} to get nginx started"
|
299
|
+
log.info 'synapse: this can fail if nginx is already running'
|
300
|
+
begin
|
301
|
+
`#{opts['start_command']}`.chomp
|
302
|
+
rescue Exception => e
|
303
|
+
log.warn "synapse: error in NGINX start: #{e.inspect}"
|
304
|
+
log.warn e.backtrace
|
305
|
+
ensure
|
306
|
+
@has_started = true
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
292
310
|
# restarts nginx if the time is right
|
293
311
|
def restart
|
294
312
|
if @time < @next_restart
|
@@ -299,13 +317,8 @@ class Synapse::ConfigGenerator
|
|
299
317
|
@next_restart = @time + @restart_interval
|
300
318
|
@next_restart += rand(@restart_jitter * @restart_interval + 1)
|
301
319
|
|
302
|
-
#
|
303
|
-
unless @has_started
|
304
|
-
log.info "synapse: attempting to run #{opts['start_command']} to get nginx started"
|
305
|
-
log.info 'synapse: this can fail if nginx is already running'
|
306
|
-
res = `#{opts['start_command']}`.chomp
|
307
|
-
@has_started = true
|
308
|
-
end
|
320
|
+
# On the very first restart we may need to start
|
321
|
+
start unless @has_started
|
309
322
|
|
310
323
|
res = `#{opts['reload_command']}`.chomp
|
311
324
|
unless $?.success?
|
@@ -94,4 +94,69 @@ describe Synapse::ConfigGenerator::Nginx do
|
|
94
94
|
subject.update_config(watchers)
|
95
95
|
end
|
96
96
|
end
|
97
|
+
|
98
|
+
describe '#update_config' do
|
99
|
+
let(:watchers) { [mockwatcher] }
|
100
|
+
|
101
|
+
shared_context 'generate_config is stubbed out' do
|
102
|
+
let(:new_config) { 'this is a new config!' }
|
103
|
+
before { allow(subject).to receive(:generate_config).and_return(new_config) }
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'always updates the config' do
|
107
|
+
expect(subject).to receive(:generate_config).with(watchers)
|
108
|
+
subject.update_config(watchers)
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'if we support config writes' do
|
112
|
+
include_context 'generate_config is stubbed out'
|
113
|
+
before { config['nginx']['do_writes'] = true }
|
114
|
+
|
115
|
+
it 'writes the new config' do
|
116
|
+
expect(subject).to receive(:write_config).with(new_config)
|
117
|
+
subject.update_config(watchers)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when we support config writes and reloads' do
|
122
|
+
include_context 'generate_config is stubbed out'
|
123
|
+
|
124
|
+
before do
|
125
|
+
config['nginx']['do_writes'] = true
|
126
|
+
config['nginx']['do_reloads'] = true
|
127
|
+
allow(subject).to receive(:write_config).and_return(true)
|
128
|
+
allow(subject).to receive(:`).and_return('it worked')
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'always does a restarts and only starts once' do
|
132
|
+
expect(subject).to receive(:write_config).with(new_config).twice
|
133
|
+
expect(subject).to receive(:restart).twice.and_call_original
|
134
|
+
expect(subject).to receive(:start).once.and_call_original
|
135
|
+
subject.update_config(watchers)
|
136
|
+
subject.update_config(watchers)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#tick' do
|
142
|
+
let(:watchers) { [mockwatcher] }
|
143
|
+
|
144
|
+
context 'when we support reloads' do
|
145
|
+
before do
|
146
|
+
config['nginx']['do_reloads'] = true
|
147
|
+
config['nginx']['start_command'] = 'foo'
|
148
|
+
config['nginx']['reload_command'] = 'bar'
|
149
|
+
allow(subject).to receive(:start)
|
150
|
+
allow(subject).to receive(:restart)
|
151
|
+
allow(subject).to receive(:`).and_return('it worked')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'does start once' do
|
155
|
+
expect(subject).to receive(:start).once.and_call_original
|
156
|
+
expect(subject).not_to receive(:restart)
|
157
|
+
subject.tick(watchers)
|
158
|
+
subject.tick(watchers)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
97
162
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synapse-nginx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Lynch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: synapse
|