lacquer 0.5.7 → 0.5.8
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.
- data/README.rdoc +5 -1
- data/lib/generators/lacquer/templates/varnishd.yml +3 -0
- data/lib/lacquer/tasks.rb +6 -0
- data/lib/lacquer/varnish.rb +2 -1
- data/lib/lacquer/varnishd.rb +19 -3
- data/lib/lacquer/version.rb +1 -1
- data/spec/config/varnishd.yml +1 -0
- data/spec/lacquer/varnish_spec.rb +6 -6
- data/spec/lacquer/varnishd_spec.rb +42 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -59,19 +59,22 @@ config/varnishd.yml
|
|
59
59
|
development:
|
60
60
|
listen: localhost:3001
|
61
61
|
telnet: localhost:6082
|
62
|
-
sbin_path: /usr/local/sbin
|
62
|
+
sbin_path: /usr/local/sbin # path to varnishd
|
63
|
+
bin_path: /usr/local/bin # path to varnishadm
|
63
64
|
storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
|
64
65
|
|
65
66
|
test:
|
66
67
|
listen: localhost:3002
|
67
68
|
telnet: localhost:6083
|
68
69
|
sbin_path: /usr/local/sbin
|
70
|
+
bin_path: /usr/local/bin
|
69
71
|
storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
|
70
72
|
|
71
73
|
production:
|
72
74
|
listen: :80
|
73
75
|
telnet: localhost:6082
|
74
76
|
sbin_path: /usr/local/sbin
|
77
|
+
bin_path: /usr/local/bin
|
75
78
|
storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
|
76
79
|
params:
|
77
80
|
overflow_max: 2000 # for Varnish 2.x ... use "queue_max: 2000" for Varnish 3.x
|
@@ -188,6 +191,7 @@ Control varnishd with the following rake tasks
|
|
188
191
|
rake lacquer:varnishd:start
|
189
192
|
rake lacquer:varnishd:stop
|
190
193
|
rake lacquer:varnishd:restart
|
194
|
+
rake lacquer:varnishd:reload
|
191
195
|
rake lacquer:varnishd:status
|
192
196
|
rake lacquer:varnishd:global_purge
|
193
197
|
|
@@ -3,6 +3,7 @@ development:
|
|
3
3
|
telnet: 127.0.0.1:6082
|
4
4
|
backend: 127.0.0.1:3000
|
5
5
|
sbin_path: /usr/local/sbin
|
6
|
+
bin_path: /usr/local/bin
|
6
7
|
storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
|
7
8
|
|
8
9
|
test:
|
@@ -10,6 +11,7 @@ test:
|
|
10
11
|
telnet: 127.0.0.1:6083
|
11
12
|
backend: 127.0.0.1:3000
|
12
13
|
sbin_path: /usr/local/sbin
|
14
|
+
bin_path: /usr/local/bin
|
13
15
|
storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
|
14
16
|
|
15
17
|
production:
|
@@ -18,6 +20,7 @@ production:
|
|
18
20
|
backend: backend_server:8080
|
19
21
|
use_sudo: false
|
20
22
|
sbin_path: /usr/local/sbin
|
23
|
+
bin_path: /usr/local/bin
|
21
24
|
pid_path: <%= Rails.root.join('log') %>
|
22
25
|
storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
|
23
26
|
params:
|
data/lib/lacquer/tasks.rb
CHANGED
@@ -29,6 +29,12 @@ namespace :lacquer do
|
|
29
29
|
varnishd.start
|
30
30
|
end
|
31
31
|
|
32
|
+
desc "Reload VCL configuration through varnishadm with Lacquer's settings"
|
33
|
+
task :reload => :environment do
|
34
|
+
varnishd = Lacquer::Varnishd.new
|
35
|
+
varnishd.reload
|
36
|
+
end
|
37
|
+
|
32
38
|
desc "Purge ALL urls from Varnish"
|
33
39
|
task :global_purge => :environment do
|
34
40
|
Lacquer::Varnish.new.purge('.*')
|
data/lib/lacquer/varnish.rb
CHANGED
@@ -47,7 +47,6 @@ module Lacquer
|
|
47
47
|
digest << salt
|
48
48
|
digest << "\n"
|
49
49
|
digest << server[:secret]
|
50
|
-
digest << "\n"
|
51
50
|
digest << salt
|
52
51
|
digest << "\n"
|
53
52
|
|
@@ -71,6 +70,8 @@ module Lacquer
|
|
71
70
|
:error_message => "Error while trying to connect to #{server[:host]}:#{server[:port]}: #{e}",
|
72
71
|
:parameters => server,
|
73
72
|
:response => response })
|
73
|
+
elsif e.kind_of?(Lacquer::AuthenticationError)
|
74
|
+
raise e
|
74
75
|
else
|
75
76
|
raise VarnishError.new("Error while trying to connect to #{server[:host]}:#{server[:port]} #{e}")
|
76
77
|
end
|
data/lib/lacquer/varnishd.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Lacquer
|
2
2
|
class Varnishd
|
3
|
-
attr_accessor :listen, :telnet, :sbin_path, :storage, :working_dir, :user, :backend, :params, :use_sudo, :pid_path
|
3
|
+
attr_accessor :listen, :telnet, :sbin_path, :bin_path, :storage, :working_dir, :user, :backend, :params, :use_sudo, :pid_path
|
4
4
|
|
5
5
|
cattr_accessor :started_check_delay, :vcl_script_filename
|
6
6
|
self.started_check_delay = 1
|
@@ -23,8 +23,8 @@ module Lacquer
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def initialize(settings = self.class.config)
|
26
|
-
self.listen, self.telnet, self.backend, self.sbin_path, self.storage, self.working_dir, self.user, self.params, self.use_sudo, self.pid_path =
|
27
|
-
settings.values_at("listen", "telnet", "backend", "sbin_path", "storage", "working_dir", "user", "params", "use_sudo", "pid_path")
|
26
|
+
self.listen, self.telnet, self.backend, self.sbin_path, self.bin_path, self.storage, self.working_dir, self.user, self.params, self.use_sudo, self.pid_path =
|
27
|
+
settings.values_at("listen", "telnet", "backend", "sbin_path", "bin_path", "storage", "working_dir", "user", "params", "use_sudo", "pid_path")
|
28
28
|
end
|
29
29
|
|
30
30
|
def render_vcl
|
@@ -62,6 +62,18 @@ module Lacquer
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
def reload
|
66
|
+
if running?
|
67
|
+
generate_vcl
|
68
|
+
reload_id = "reload#{Time.now.usec}"
|
69
|
+
load_cmd = "#{varnishadm_cmd} vcl.load #{reload_id} #{options['-f']}"
|
70
|
+
use_cmd = "#{varnishadm_cmd} vcl.use #{reload_id}"
|
71
|
+
execute "#{load_cmd} && #{use_cmd}"
|
72
|
+
else
|
73
|
+
start
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
65
77
|
def running?
|
66
78
|
!!pid && !!execute("ps p #{pid}").include?(pid.to_s) # works with sudo
|
67
79
|
end
|
@@ -96,6 +108,10 @@ module Lacquer
|
|
96
108
|
"#{'sudo ' if use_sudo}#{Pathname.new(sbin_path).join('varnishd')}"
|
97
109
|
end
|
98
110
|
|
111
|
+
def varnishadm_cmd
|
112
|
+
"#{'sudo ' if use_sudo}#{Pathname.new(bin_path).join('varnishadm')} -T #{options['-T']}"
|
113
|
+
end
|
114
|
+
|
99
115
|
def pid_file
|
100
116
|
pid_computed_path.join("varnishd.#{self.class.env}.pid")
|
101
117
|
end
|
data/lib/lacquer/version.rb
CHANGED
data/spec/config/varnishd.yml
CHANGED
@@ -44,13 +44,13 @@ describe "Varnish" do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should return successfully when using correct secret" do
|
47
|
-
@telnet_mock.stub!(:waitfor).with("Match" => /^107/).and_yield(
|
48
|
-
@telnet_mock.stub!(:cmd).with("String" => "auth
|
47
|
+
@telnet_mock.stub!(:waitfor).with("Match" => /^107/).and_yield("107 59 \nhaalpffwlcvblmdrinpnjwigwsbiiigq\n\nAuthentication required.\n\n")
|
48
|
+
@telnet_mock.stub!(:cmd).with("String" => "auth a4aefcde4b0ee27268af1c9ed613e3220601276b48f9ae5914f801db6c8ef612", "Match" => /\d{3}/).and_yield('200')
|
49
49
|
@telnet_mock.stub!(:cmd).with("String" => "url.purge /", "Match" => /\n\n/).and_yield('200')
|
50
50
|
|
51
51
|
lambda {
|
52
52
|
Lacquer::Varnish.new.purge('/')
|
53
|
-
}.should_not raise_error
|
53
|
+
}.should_not raise_error(Lacquer::AuthenticationError)
|
54
54
|
end
|
55
55
|
|
56
56
|
after(:each) do
|
@@ -63,13 +63,13 @@ describe "Varnish" do
|
|
63
63
|
Lacquer.configuration.varnish_servers.first[:secret] = "the wrong secret"
|
64
64
|
end
|
65
65
|
it "should raise Lacquer::AuthenticationError when using wrong secret" do
|
66
|
-
@telnet_mock.stub!(:waitfor).with("Match" => /^107/).and_yield(
|
67
|
-
@telnet_mock.stub!(:cmd).with("String" => "auth
|
66
|
+
@telnet_mock.stub!(:waitfor).with("Match" => /^107/).and_yield("107 59 \nhaalpffwlcvblmdrinpnjwigwsbiiigq\n\nAuthentication required.\n\n")
|
67
|
+
@telnet_mock.stub!(:cmd).with("String" => "auth 767dc6ec9eca6e4155d20c8479d3a1a10cf88d92c3846388a830d7fd966d58f9", "Match" => /\d{3}/).and_yield('107')
|
68
68
|
@telnet_mock.stub!(:cmd).with("url.purge /").and_yield('200')
|
69
69
|
|
70
70
|
lambda {
|
71
71
|
Lacquer::Varnish.new.purge('/')
|
72
|
-
}.should raise_error(Lacquer::
|
72
|
+
}.should raise_error(Lacquer::AuthenticationError)
|
73
73
|
end
|
74
74
|
after(:each) do
|
75
75
|
Lacquer.configuration.varnish_servers.first[:secret] = nil
|
@@ -26,6 +26,7 @@ describe "Varnishd" do
|
|
26
26
|
Lacquer::Varnishd.config.should have_key("listen")
|
27
27
|
Lacquer::Varnishd.config.should have_key("telnet")
|
28
28
|
Lacquer::Varnishd.config.should have_key("sbin_path")
|
29
|
+
Lacquer::Varnishd.config.should have_key("bin_path")
|
29
30
|
Lacquer::Varnishd.config.should have_key("storage")
|
30
31
|
Lacquer::Varnishd.config.should have_key("use_sudo")
|
31
32
|
Lacquer::Varnishd.config["params"].should have_key('overflow_max')
|
@@ -77,4 +78,45 @@ describe "Varnishd" do
|
|
77
78
|
result.should include('.host = "0.0.0.0"')
|
78
79
|
result.should include('.port = "3000"')
|
79
80
|
end
|
81
|
+
|
82
|
+
describe '#reload' do
|
83
|
+
def expect_reload_cmd(attributes)
|
84
|
+
Time.stub(:now).and_return Time.parse('October 6th, 1984')
|
85
|
+
varnishadm_cmd = "#{attributes['bin_path']}/varnishadm -T #{attributes['telnet']}"
|
86
|
+
reload_id = "reload#{Time.now.usec}"
|
87
|
+
load_cmd = "#{varnishadm_cmd} vcl.load #{reload_id} config/generate.vcl"
|
88
|
+
use_cmd = "#{varnishadm_cmd} vcl.use #{reload_id}"
|
89
|
+
|
90
|
+
executes_with "#{load_cmd} && #{use_cmd}"
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'given varnishd is running' do
|
94
|
+
before do
|
95
|
+
attributes = { "sbin_path" => "/opt/varnishd/sbin", "bin_path" => "/opt/bin", "telnet" => "localhost:6082" }
|
96
|
+
expect_reload_cmd attributes
|
97
|
+
@varnishd = Lacquer::Varnishd.new attributes
|
98
|
+
@varnishd.stub(:vcl_script_filename).and_return("config/generate.vcl")
|
99
|
+
@varnishd.stub(:running?).and_return true
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'executes the varnishadm reload commands' do
|
103
|
+
@varnishd.should_receive :generate_vcl
|
104
|
+
end
|
105
|
+
|
106
|
+
after do
|
107
|
+
@varnishd.reload
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'given varnishd is not running' do
|
112
|
+
before do
|
113
|
+
executes_with(%r[/opt/varnishd/sbin/varnishd])
|
114
|
+
@varnishd = Lacquer::Varnishd.new("sbin_path" => "/opt/varnishd/sbin")
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'starts varnishd' do
|
118
|
+
@varnishd.reload
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
80
122
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lacquer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2012-
|
15
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|