lacquer 0.4.0 → 0.6.6
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 +7 -0
- data/.gitignore +4 -20
- data/.travis.yml +3 -0
- data/Gemfile +2 -7
- data/README.md +260 -0
- data/Rakefile +11 -33
- data/init.rb +1 -1
- data/lacquer.gemspec +19 -69
- data/lib/generators/lacquer/install_generator.rb +5 -1
- data/lib/generators/lacquer/templates/initializer.rb +15 -3
- data/lib/generators/lacquer/templates/{varnish.sample.vcl → varnish.vcl.erb} +27 -27
- data/lib/generators/lacquer/templates/varnishd.yml +31 -0
- data/lib/lacquer/cache_control.rb +75 -0
- data/lib/lacquer/cache_utils.rb +14 -12
- data/lib/lacquer/capistrano/v2/hooks.rb +21 -0
- data/lib/lacquer/capistrano/v3/tasks/lacquer.rake +24 -0
- data/lib/lacquer/capistrano.rb +7 -0
- data/lib/lacquer/configuration.rb +12 -0
- data/lib/lacquer/delayed_job_job.rb +2 -2
- data/lib/lacquer/railtie.rb +9 -0
- data/lib/lacquer/recipes.rb +62 -0
- data/lib/lacquer/resque_job.rb +2 -2
- data/lib/lacquer/sidekiq_worker.rb +11 -0
- data/lib/lacquer/tasks.rb +48 -0
- data/lib/lacquer/varnish.rb +35 -4
- data/lib/lacquer/varnishd.rb +152 -0
- data/lib/lacquer/version.rb +3 -0
- data/lib/lacquer.rb +9 -0
- data/rails/init.rb +1 -1
- data/recipes/lacquer.rb +1 -0
- data/spec/config/generate.vcl.erb +15 -0
- data/spec/config/varnish.vcl +15 -0
- data/spec/config/varnishd.yml +12 -0
- data/spec/lacquer/cache_control_spec.rb +74 -0
- data/spec/lacquer/cache_utils_spec.rb +20 -8
- data/spec/lacquer/delayed_job_job_spec.rb +4 -2
- data/spec/lacquer/resque_job_spec.rb +4 -2
- data/spec/lacquer/sidekiq_worker_spec.rb +15 -0
- data/spec/lacquer/varnish_spec.rb +62 -18
- data/spec/lacquer/varnishd_spec.rb +122 -0
- data/spec/spec_helper.rb +13 -1
- data/tasks/lacquer.rake +1 -0
- metadata +135 -66
- data/.bundle/config +0 -2
- data/Gemfile.lock +0 -39
- data/README.rdoc +0 -83
- data/VERSION +0 -1
@@ -0,0 +1,75 @@
|
|
1
|
+
module Lacquer
|
2
|
+
def self.cache_control
|
3
|
+
@cache_control ||= CacheControl.new
|
4
|
+
end
|
5
|
+
|
6
|
+
class CacheControl
|
7
|
+
include Lacquer::CacheUtils
|
8
|
+
attr_accessor :store
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.store = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def register(group, options = {})
|
15
|
+
options[:group] = group
|
16
|
+
options[:args] = Array(options[:args]).compact
|
17
|
+
store << options
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure
|
21
|
+
yield self
|
22
|
+
end
|
23
|
+
|
24
|
+
def purge(group, *args)
|
25
|
+
clear_cache_for(*urls_for(group, *args))
|
26
|
+
end
|
27
|
+
|
28
|
+
def urls_for(group, *args)
|
29
|
+
args.map! { |arg| arg.to_param }
|
30
|
+
urls_by(group).map { |options| options[:url] % args }
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_vcl_conditions(urls = store)
|
34
|
+
urls.map { |opt| %Q[req.url ~ "#{(opt[:url] % opt[:args])}"] }.join(" || ")
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_vcl_override_ttl_urls
|
38
|
+
urls_grouped_by_expires.map do |expires_in, list|
|
39
|
+
<<-CODE.gsub(/^[ \t]{4}*/, '')
|
40
|
+
if(#{to_vcl_conditions(list)}) {
|
41
|
+
unset beresp.http.Set-Cookie;
|
42
|
+
set beresp.ttl = #{expires_in};
|
43
|
+
return(deliver);
|
44
|
+
}
|
45
|
+
CODE
|
46
|
+
end.join("\n")
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_vcl_pass_urls
|
50
|
+
<<-CODE.gsub(/^[ \t]{4}*/, '')
|
51
|
+
if(#{to_vcl_conditions(urls_by(:pass))}) {
|
52
|
+
return(pass);
|
53
|
+
}
|
54
|
+
CODE
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_vcl_pipe_urls
|
58
|
+
<<-CODE.gsub(/^[ \t]{4}*/, '')
|
59
|
+
if(#{to_vcl_conditions(urls_by(:pipe))}) {
|
60
|
+
return(pipe);
|
61
|
+
}
|
62
|
+
CODE
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
def urls_grouped_by_expires
|
68
|
+
store.group_by { |opt| opt[:expires_in] }.select { |expires_in, list| expires_in }
|
69
|
+
end
|
70
|
+
|
71
|
+
def urls_by(group)
|
72
|
+
store.select { |opt| opt[:group] == group }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/lacquer/cache_utils.rb
CHANGED
@@ -26,20 +26,22 @@ module Lacquer
|
|
26
26
|
#
|
27
27
|
# clear_cache_for(root_path, blog_posts_path, '/other/content/*')
|
28
28
|
def clear_cache_for(*paths)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
29
|
+
return unless Lacquer.configuration.enable_cache
|
30
|
+
case Lacquer.configuration.job_backend
|
31
|
+
when :delayed_job
|
32
|
+
require 'lacquer/delayed_job_job'
|
33
|
+
Delayed::Job.enqueue(Lacquer::DelayedJobJob.new(paths))
|
34
|
+
when :resque
|
35
|
+
require 'lacquer/resque_job'
|
36
|
+
Resque.enqueue(Lacquer::ResqueJob, paths)
|
37
|
+
when :sidekiq
|
38
|
+
require 'lacquer/sidekiq_worker'
|
39
|
+
Lacquer::SidekiqWorker.perform_async(paths)
|
40
|
+
when :none
|
41
|
+
Varnish.new.purge(*paths)
|
40
42
|
end
|
41
43
|
end
|
42
|
-
|
44
|
+
|
43
45
|
# Sends cache control headers with page.
|
44
46
|
# These are the headers that varnish responds to
|
45
47
|
# to set cache properly.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Capistrano tasks for Lacquer
|
2
|
+
|
3
|
+
Capistrano::Configuration.instance(:must_exit).load do
|
4
|
+
_cset(:lacquer_roles) { :web }
|
5
|
+
|
6
|
+
after "deploy:web:disable", "lacquer:global_purge"
|
7
|
+
after "deploy:web:enable", "lacquer:global_purge"
|
8
|
+
after "deploy:rollback", "lacquer:global_purge"
|
9
|
+
after "deploy:rollback", "lacquer:restart"
|
10
|
+
after "deploy:update", "lacquer:restart"
|
11
|
+
|
12
|
+
namespace :lacquer do
|
13
|
+
%w( start stop restart global_purge status ).each do |name|
|
14
|
+
desc "#{name} varnish"
|
15
|
+
task name.to_sym, :roles => lacquer_roles do
|
16
|
+
next if find_servers_for_task(current_task).empty?
|
17
|
+
run "cd #{current_path} && #{rake} lacquer:varnishd:#{name}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
set :lacquer_roles, -> { :web }
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
namespace :lacquer do
|
8
|
+
%w( start stop restart purge global_purge status ).each do |name|
|
9
|
+
desc "#{name} varnish"
|
10
|
+
task name.to_sym do
|
11
|
+
on roles(fetch(:lacquer_roles)) do
|
12
|
+
within release_path do
|
13
|
+
with rails_env: fetch(:rails_env) do
|
14
|
+
execute :bundle, "exec rake", "lacquer:varnishd:#{name}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after "deploy:rollback", "lacquer:global_purge"
|
22
|
+
after "deploy:rollback", "lacquer:restart"
|
23
|
+
after "deploy:updated", "lacquer:restart"
|
24
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'capistrano/version'
|
2
|
+
|
3
|
+
if defined?(Capistrano::VERSION) && Gem::Version.new(Capistrano::VERSION).release >= Gem::Version.new('3.0.0')
|
4
|
+
load File.expand_path("../capistrano/v3/tasks/lacquer.rake", __FILE__)
|
5
|
+
else
|
6
|
+
require 'lacquer/capistrano/v2/hooks'
|
7
|
+
end
|
@@ -20,6 +20,15 @@ module Lacquer
|
|
20
20
|
# Error handler
|
21
21
|
attr_accessor :command_error_handler
|
22
22
|
|
23
|
+
# Purge Command
|
24
|
+
attr_accessor :purge_command
|
25
|
+
|
26
|
+
# Pass Command (in vcl_fetch)
|
27
|
+
attr_accessor :pass_command
|
28
|
+
|
29
|
+
# Use sudo for start up
|
30
|
+
attr_accessor :use_sudo
|
31
|
+
|
23
32
|
def initialize
|
24
33
|
@enable_cache = true
|
25
34
|
@varnish_servers = []
|
@@ -27,6 +36,9 @@ module Lacquer
|
|
27
36
|
@job_backend = :none
|
28
37
|
@retries = 5
|
29
38
|
@command_error_handler = nil
|
39
|
+
@purge_command = "url.purge"
|
40
|
+
@pass_command = "pass"
|
41
|
+
@use_sudo = false
|
30
42
|
end
|
31
43
|
|
32
44
|
# Returns a hash of all configurable options
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Capistrano Recipes for managing varnishd
|
2
|
+
#
|
3
|
+
# Add these callbacks to have the varnishd process restart when the server
|
4
|
+
# is restarted:
|
5
|
+
#
|
6
|
+
# after "deploy:stop", "delayed_job:stop"
|
7
|
+
# after "deploy:start", "delayed_job:start"
|
8
|
+
# after "deploy:restart", "delayed_job:restart"
|
9
|
+
#
|
10
|
+
# If you've got varnishd running on a servers, you can also specify
|
11
|
+
# which servers have varnishd running and should be restarted after deploy.
|
12
|
+
#
|
13
|
+
# set :varnishd_role, :varnish
|
14
|
+
#
|
15
|
+
|
16
|
+
Capistrano::Configuration.instance.load do
|
17
|
+
namespace :varnishd do
|
18
|
+
def rails_env
|
19
|
+
fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
|
20
|
+
end
|
21
|
+
|
22
|
+
def rake
|
23
|
+
fetch(:rake, 'rake')
|
24
|
+
end
|
25
|
+
|
26
|
+
def roles
|
27
|
+
fetch(:varnishd_role, :varnish)
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Link varnishd.yml from shared/config to app/config"
|
31
|
+
task :link_varnishd_yml, :roles => lambda { roles } do
|
32
|
+
run "cd #{release_path} && ln -nfs #{shared_path}/config/varnishd.yml #{release_path}/config/varnishd.yml"
|
33
|
+
end
|
34
|
+
after 'deploy:update_code', 'varnishd:link_varnishd_yml'
|
35
|
+
|
36
|
+
desc "Link varnish.vcl from shared/config to app/config"
|
37
|
+
task :link_varnish_vcl, :roles => lambda { roles } do
|
38
|
+
run "cd #{release_path} && ln -nfs #{shared_path}/config/varnish.vcl #{release_path}/config/varnish.vcl"
|
39
|
+
end
|
40
|
+
after 'deploy:update_code', 'varnishd:link_varnishd_vcl'
|
41
|
+
|
42
|
+
desc "Purge ALL urls from Varnish"
|
43
|
+
task :global_purge, :roles => lambda { roles } do
|
44
|
+
run "cd #{current_path};#{rails_env} #{rake} varnishd:global_purge"
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Stop the varnishd process"
|
48
|
+
task :stop, :roles => lambda { roles } do
|
49
|
+
run "cd #{current_path};#{rails_env} #{rake} varnishd:stop"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Start the varnishd process"
|
53
|
+
task :start, :roles => lambda { roles } do
|
54
|
+
run "cd #{current_path};#{rails_env} #{rake} varnishd:start"
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "Restart the delayed_job process"
|
58
|
+
task :restart, :roles => lambda { roles } do
|
59
|
+
run "cd #{current_path};#{rails_env} #{rake} varnishd:restart"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/lacquer/resque_job.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
namespace :lacquer do
|
2
|
+
namespace :varnishd do
|
3
|
+
desc "Start varnishd daemon using Lacquer's settings"
|
4
|
+
task :start => :environment do
|
5
|
+
Lacquer::Varnishd.new.start
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Stop varnishd daemon using Lacquer's settings"
|
9
|
+
task :stop => :environment do
|
10
|
+
Lacquer::Varnishd.new.stop
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Running status of varnishd daemon using Lacquer's settings"
|
14
|
+
task :status => :environment do
|
15
|
+
if Lacquer::Varnishd.new.running?
|
16
|
+
puts "Varnishd is running"
|
17
|
+
else
|
18
|
+
puts "Varnishd is not running"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Restart varnishd daemon using Lacquer's settings"
|
23
|
+
task :restart => :environment do
|
24
|
+
varnishd = Lacquer::Varnishd.new
|
25
|
+
if varnishd.running?
|
26
|
+
varnishd.stop
|
27
|
+
sleep(1)
|
28
|
+
end
|
29
|
+
varnishd.start
|
30
|
+
end
|
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
|
+
|
38
|
+
desc "Purge a urls from Varnish"
|
39
|
+
task :purge => :environment do
|
40
|
+
Lacquer::Varnish.new.purge(ENV['PURGE'].to_s)
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Purge ALL urls from Varnish"
|
44
|
+
task :global_purge => :environment do
|
45
|
+
Lacquer::Varnish.new.purge('.*')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/lacquer/varnish.rb
CHANGED
@@ -12,9 +12,14 @@ module Lacquer
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# Sends the command 'url.purge *path*'
|
15
|
-
def purge(
|
16
|
-
|
17
|
-
|
15
|
+
def purge(*paths)
|
16
|
+
paths.all? do |path|
|
17
|
+
ActiveSupport::Notifications.instrument('purge.lacquer', path: path) do |payload|
|
18
|
+
send_command(Lacquer.configuration.purge_command + " " + path.gsub('\\', '\\\\\\')).all? do |result|
|
19
|
+
payload[:result] = result
|
20
|
+
result =~ /200/
|
21
|
+
end
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
@@ -29,8 +34,32 @@ module Lacquer
|
|
29
34
|
'Host' => server[:host],
|
30
35
|
'Port' => server[:port],
|
31
36
|
'Timeout' => server[:timeout] || 5)
|
37
|
+
|
38
|
+
if(server[:secret])
|
39
|
+
connection.waitfor("Match" => /^107/) do |authentication_request|
|
40
|
+
matchdata = /^107 \d{2}\s*(.{32}).*$/m.match(authentication_request) # Might be a bit ugly regex, but it works great!
|
41
|
+
salt = matchdata[1]
|
42
|
+
if(salt.empty?)
|
43
|
+
raise VarnishError, "Bad authentication request"
|
44
|
+
end
|
45
|
+
|
46
|
+
digest = OpenSSL::Digest.new('sha256')
|
47
|
+
digest << salt
|
48
|
+
digest << "\n"
|
49
|
+
digest << server[:secret]
|
50
|
+
digest << salt
|
51
|
+
digest << "\n"
|
52
|
+
|
53
|
+
connection.cmd("String" => "auth #{digest.to_s}", "Match" => /\d{3}/) do |auth_response|
|
54
|
+
if(!(/^200/ =~ auth_response))
|
55
|
+
raise AuthenticationError, "Could not authenticate"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
32
61
|
connection.cmd('String' => command, 'Match' => /\n\n/) {|r| response = r.split("\n").first.strip}
|
33
|
-
connection.close
|
62
|
+
connection.close if connection.respond_to?(:close)
|
34
63
|
rescue Exception => e
|
35
64
|
if retries < Lacquer.configuration.retries
|
36
65
|
retry
|
@@ -41,6 +70,8 @@ module Lacquer
|
|
41
70
|
:error_message => "Error while trying to connect to #{server[:host]}:#{server[:port]}: #{e}",
|
42
71
|
:parameters => server,
|
43
72
|
:response => response })
|
73
|
+
elsif e.kind_of?(Lacquer::AuthenticationError)
|
74
|
+
raise e
|
44
75
|
else
|
45
76
|
raise VarnishError.new("Error while trying to connect to #{server[:host]}:#{server[:port]} #{e}")
|
46
77
|
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
module Lacquer
|
2
|
+
class Varnishd
|
3
|
+
attr_accessor :listen, :telnet, :sbin_path, :bin_path, :storage, :working_dir, :user, :backend, :params, :use_sudo, :pid_path
|
4
|
+
|
5
|
+
cattr_accessor :started_check_delay, :vcl_script_filename
|
6
|
+
self.started_check_delay = 1
|
7
|
+
self.vcl_script_filename = 'config/varnish.vcl'
|
8
|
+
|
9
|
+
def self.root_path
|
10
|
+
Rails.root
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.env
|
14
|
+
Rails.env
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.config_file
|
18
|
+
root_path.join('config/varnishd.yml')
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.config
|
22
|
+
YAML.load(File.read(config_file))[env].stringify_keys
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(settings = self.class.config)
|
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
|
+
end
|
29
|
+
|
30
|
+
def render_vcl
|
31
|
+
require 'erubis'
|
32
|
+
eruby = Erubis::Eruby.new(erb_vcl_script_filename.read)
|
33
|
+
eruby.result(binding)
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_vcl
|
37
|
+
if erb_vcl_script_filename.exist?
|
38
|
+
log "#{erb_vcl_script_filename} found rendering to #{vcl_script_filename}"
|
39
|
+
File.open(vcl_script_filename, "w") do |vcl|
|
40
|
+
vcl.write(render_vcl)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def start
|
46
|
+
if running?
|
47
|
+
log("Already running")
|
48
|
+
return
|
49
|
+
end
|
50
|
+
generate_vcl
|
51
|
+
execute("#{varnishd_cmd} #{args} #{params_args}")
|
52
|
+
sleep(self.class.started_check_delay)
|
53
|
+
log("Failed to start varnishd daemon") unless running?
|
54
|
+
end
|
55
|
+
|
56
|
+
def stop
|
57
|
+
if running?
|
58
|
+
execute("#{'sudo ' if use_sudo}kill #{pid}")
|
59
|
+
pid_file.delete
|
60
|
+
else
|
61
|
+
log("pid file not found or varnishd not running")
|
62
|
+
end
|
63
|
+
end
|
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
|
+
|
77
|
+
def running?
|
78
|
+
!!pid && !!execute("ps p #{pid}").include?(pid.to_s) # works with sudo
|
79
|
+
end
|
80
|
+
|
81
|
+
def args
|
82
|
+
options.map { |k, v| "#{k} #{v}" }.join(" ")
|
83
|
+
end
|
84
|
+
|
85
|
+
def params_args
|
86
|
+
params.map { |k, v| "-p #{k}=#{v}" }.join(" ")
|
87
|
+
end
|
88
|
+
|
89
|
+
def options
|
90
|
+
opt = {}
|
91
|
+
opt["-P"] = pid_file
|
92
|
+
opt["-a"] = listen
|
93
|
+
opt["-T"] = telnet if telnet.present?
|
94
|
+
opt["-n"] = working_dir if working_dir.present?
|
95
|
+
opt["-u"] = user if user.present?
|
96
|
+
opt["-s"] = eval(%Q("#{storage}"))
|
97
|
+
opt["-f"] = vcl_script_filename
|
98
|
+
opt
|
99
|
+
end
|
100
|
+
|
101
|
+
def params
|
102
|
+
@params || {}
|
103
|
+
end
|
104
|
+
|
105
|
+
protected
|
106
|
+
|
107
|
+
def varnishd_cmd
|
108
|
+
"#{'sudo ' if use_sudo}#{Pathname.new(sbin_path).join('varnishd')}"
|
109
|
+
end
|
110
|
+
|
111
|
+
def varnishadm_cmd
|
112
|
+
"#{'sudo ' if use_sudo}#{Pathname.new(bin_path).join('varnishadm')} -T #{options['-T']}"
|
113
|
+
end
|
114
|
+
|
115
|
+
def pid_file
|
116
|
+
pid_computed_path.join("varnishd.#{self.class.env}.pid")
|
117
|
+
end
|
118
|
+
|
119
|
+
def pid_computed_path
|
120
|
+
if self.pid_path
|
121
|
+
Pathname.new self.pid_path
|
122
|
+
else
|
123
|
+
self.class.root_path.join('log/')
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def vcl_script_filename
|
128
|
+
self.class.root_path.join(self.class.vcl_script_filename)
|
129
|
+
end
|
130
|
+
|
131
|
+
def erb_vcl_script_filename
|
132
|
+
vcl_script_filename.sub_ext('.vcl.erb')
|
133
|
+
end
|
134
|
+
|
135
|
+
def log(message)
|
136
|
+
puts "** [#{self.class.name}] #{message}"
|
137
|
+
end
|
138
|
+
|
139
|
+
def execute(cmd)
|
140
|
+
log(cmd)
|
141
|
+
`#{cmd}`
|
142
|
+
end
|
143
|
+
|
144
|
+
def pid
|
145
|
+
if pid_file.exist?
|
146
|
+
pid_file.read
|
147
|
+
else
|
148
|
+
nil
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
data/lib/lacquer.rb
CHANGED
@@ -1,13 +1,22 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "net/telnet"
|
3
|
+
|
4
|
+
require "openssl"
|
5
|
+
require "digest/sha2"
|
6
|
+
|
3
7
|
require "active_support/core_ext"
|
4
8
|
|
5
9
|
require "lacquer/configuration"
|
6
10
|
require "lacquer/cache_utils"
|
11
|
+
require "lacquer/cache_control"
|
7
12
|
require "lacquer/varnish"
|
13
|
+
require "lacquer/varnishd"
|
14
|
+
|
15
|
+
require "lacquer/railtie" if defined?(Rails::Railtie)
|
8
16
|
|
9
17
|
module Lacquer
|
10
18
|
class VarnishError < Exception; end # @private
|
19
|
+
class AuthenticationError < VarnishError; end # @private
|
11
20
|
|
12
21
|
class << self
|
13
22
|
attr_accessor :configuration
|
data/rails/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'lacquer'
|
1
|
+
require 'lacquer'
|
data/recipes/lacquer.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'lacquer', 'recipes'))
|
@@ -0,0 +1,15 @@
|
|
1
|
+
backend default {
|
2
|
+
.host = "<%= backend.split(':').first %>";
|
3
|
+
.port = "<%= backend.split(':').last %>";
|
4
|
+
}
|
5
|
+
|
6
|
+
sub vcl_recv {
|
7
|
+
set req.backend = default;
|
8
|
+
unset req.http.Cookie;
|
9
|
+
set req.grace = 30m;
|
10
|
+
}
|
11
|
+
|
12
|
+
sub vcl_fetch {
|
13
|
+
unset beresp.http.Set-Cookie;
|
14
|
+
set beresp.grace = 30m;
|
15
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
test:
|
2
|
+
listen: :80
|
3
|
+
telnet: localhost:6082
|
4
|
+
sbin_path: /usr/local/sbin
|
5
|
+
bin_path: /usr/local/bin
|
6
|
+
backend: 0.0.0.0:3000
|
7
|
+
storage: "file,#{Rails.root}/log/varnish,1GB"
|
8
|
+
working_dir: ""
|
9
|
+
user: "deploy"
|
10
|
+
use_sudo: true
|
11
|
+
params:
|
12
|
+
overflow_max: 2000
|