add varnishncsa logging
This commit is contained in:
parent
b21cfe7090
commit
599db803dc
@ -6,6 +6,7 @@ require 'fileutils'
|
|||||||
module Guard
|
module Guard
|
||||||
class Lacquer < Guard
|
class Lacquer < Guard
|
||||||
autoload :Varnishd, 'guard/lacquer/varnishd'
|
autoload :Varnishd, 'guard/lacquer/varnishd'
|
||||||
|
autoload :VarnishNCSA, 'guard/lacquer/varnishncsa'
|
||||||
|
|
||||||
def initialize(watchers = [], options = {})
|
def initialize(watchers = [], options = {})
|
||||||
super
|
super
|
||||||
@ -14,11 +15,27 @@ module Guard
|
|||||||
:port => 3001,
|
:port => 3001,
|
||||||
:backend => '127.0.0.1:3000',
|
:backend => '127.0.0.1:3000',
|
||||||
:storage => 'file,tmp/cache/varnish.store,32M',
|
:storage => 'file,tmp/cache/varnish.store,32M',
|
||||||
:sbin_path => File.split(`which varnishd`.strip).first,
|
:pid_dir => 'tmp/pids',
|
||||||
:pid_file => 'tmp/pids/varnish.pid'
|
:log_dir => 'log',
|
||||||
|
:name => File.split(Dir.pwd).last
|
||||||
}.merge(options)
|
}.merge(options)
|
||||||
|
|
||||||
@backend = Varnishd.new(@options)
|
if @options[:varnish_path]
|
||||||
|
@options.merge!(
|
||||||
|
:sbin_path => File.join(@options[:varnish_path], 'sbin'),
|
||||||
|
:bin_path => File.join(@options[:varnish_path], 'bin'),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
@options.merge!(
|
||||||
|
:sbin_path => File.split(`which varnishd`.strip).first,
|
||||||
|
:bin_path => File.split(`which varnishncsa`.strip).first
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
p @options
|
||||||
|
|
||||||
|
@frontend = Varnishd.new(@options)
|
||||||
|
@logger = VarnishNCSA.new(@options)
|
||||||
|
|
||||||
if !File.file?(varnish_erb = 'config/varnish.vcl.erb')
|
if !File.file?(varnish_erb = 'config/varnish.vcl.erb')
|
||||||
UI.info "No config/varnish.vcl.erb found, copying default from Lacquer..."
|
UI.info "No config/varnish.vcl.erb found, copying default from Lacquer..."
|
||||||
@ -29,14 +46,16 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
@backend.stop if @backend.running?
|
[ @frontend, @logger ].each do |which|
|
||||||
@backend.start
|
which.stop if which.running?
|
||||||
|
which.start
|
||||||
|
end
|
||||||
|
|
||||||
notify "Varnish started on port #{@options[:port]}, with backend #{@options[:backend]}."
|
notify "Varnish started on port #{@options[:port]}, with backend #{@options[:backend]}."
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
@backend.stop
|
[ @frontend, @logger ].each(&:stop)
|
||||||
|
|
||||||
notify "Until next time..."
|
notify "Until next time..."
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
require 'guard/lacquer'
|
||||||
|
|
||||||
require 'lacquer'
|
require 'lacquer'
|
||||||
require 'lacquer/varnishd'
|
require 'lacquer/varnishd'
|
||||||
|
|
||||||
class Guard::Lacquer::Varnishd < ::Lacquer::Varnishd
|
class Guard::Lacquer::Varnishd < ::Lacquer::Varnishd
|
||||||
attr_accessor :pid_file
|
attr_accessor :pid_dir
|
||||||
|
|
||||||
def self.root_path
|
def self.root_path
|
||||||
Pathname.new(Dir.pwd)
|
Pathname.new(Dir.pwd)
|
||||||
@ -12,14 +14,25 @@ class Guard::Lacquer::Varnishd < ::Lacquer::Varnishd
|
|||||||
ENV['RAILS_ENV'] || 'development'
|
ENV['RAILS_ENV'] || 'development'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.app_name
|
||||||
|
self.name.downcase.split("::").last
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
if options[:backend].split(':').first.empty?
|
if options[:backend].split(':').first.empty?
|
||||||
options[:backend] = "127.0.0.1#{options[:backend]}"
|
options[:backend] = "127.0.0.1#{options[:backend]}"
|
||||||
end
|
end
|
||||||
self.pid_file = self.class.root_path.join(options[:pid_file])
|
|
||||||
|
options[:working_dir] ||= options[:name]
|
||||||
|
self.pid_dir = options[:pid_dir] || 'tmp/pids'
|
||||||
|
|
||||||
options[:listen] = "127.0.0.1:#{options[:port]}"
|
options[:listen] = "127.0.0.1:#{options[:port]}"
|
||||||
|
|
||||||
super(Hash[options.collect { |k, v| [ k.to_s, v ] }])
|
super(Hash[options.collect { |k, v| [ k.to_s, v ] }])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pid_file
|
||||||
|
self.class.root_path.join(self.pid_dir).join("#{self.class.app_name}.#{self.class.env}.pid")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
47
lib/guard/lacquer/varnishncsa.rb
Normal file
47
lib/guard/lacquer/varnishncsa.rb
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
require 'guard/lacquer'
|
||||||
|
|
||||||
|
class Guard::Lacquer
|
||||||
|
class VarnishNCSA < Varnishd
|
||||||
|
attr_accessor :bin_path, :log_dir
|
||||||
|
|
||||||
|
def initialize(settings)
|
||||||
|
settings[:working_dir] ||= settings[:name]
|
||||||
|
|
||||||
|
self.working_dir, self.bin_path, self.log_dir = settings[:working_dir], settings[:bin_path], settings[:log_dir]
|
||||||
|
|
||||||
|
self.pid_dir = settings[:pid_dir] || 'tmp/pids'
|
||||||
|
end
|
||||||
|
|
||||||
|
def start
|
||||||
|
if running?
|
||||||
|
log("Aready running")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
execute("#{varnishncsa_cmd} #{args}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop
|
||||||
|
if running?
|
||||||
|
execute("kill #{pid}")
|
||||||
|
pid_file.delete
|
||||||
|
else
|
||||||
|
log("pid file not found or #{self.class.app_name} not running")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def options
|
||||||
|
opt = {}
|
||||||
|
opt["-P"] = pid_file
|
||||||
|
opt["-n"] = working_dir if working_dir.present?
|
||||||
|
opt["-a"] = '-D'
|
||||||
|
opt["-w"] = self.class.root_path.join(self.log_dir).join("varnishncsa.#{self.class.env}.log")
|
||||||
|
opt
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
def varnishncsa_cmd
|
||||||
|
Pathname.new(self.bin_path).join('varnishncsa')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user