Browse files

Added railtie revmoed rails/init

  • Loading branch information...
1 parent 3e2172e commit 182b5f5d246e10bfe4dec7e28a377c00977658c7 @jnstq jnstq committed Jan 8, 2011
Showing with 76 additions and 2 deletions.
  1. +1 −0 Rakefile
  2. +1 −1 init.rb
  3. +2 −0 lib/lacquer.rb
  4. +16 −0 lib/lacquer/railtie.rb
  5. +56 −0 lib/lacquer/tasks.rb
  6. +0 −1 rails/init.rb
View
1 Rakefile
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require "rubygems"
require "bundler/setup"
View
2 init.rb
@@ -1 +1 @@
-require File.join(File.dirname(__FILE__), 'lib', 'lacquer')
+require File.join(File.dirname(__FILE__), 'lib', 'lacquer')
View
2 lib/lacquer.rb
@@ -10,6 +10,8 @@
require "lacquer/cache_utils"
require "lacquer/varnish"
+require "lacquer/railtie" if defined?(Rails::Railtie)
+
module Lacquer
class VarnishError < Exception; end # @private
class AuthenticationError < VarnishError; end # @private
View
16 lib/lacquer/railtie.rb
@@ -0,0 +1,16 @@
+require 'lacquer'
+require 'rails'
+module Lacquer
+ class Railtie < Rails::Railtie
+ rake_tasks do
+
+ desc "hello"
+ taks :lacquer do
+ end
+
+ raise "FAIL #{__FILE__}"
+
+ load 'lacquer/tasks.rb'
+ end
+ end
+end
View
56 lib/lacquer/tasks.rb
@@ -0,0 +1,56 @@
+namespace :varnishd do
+
+ desc "Start a varnishd daemon using Lacquer's settings"
+ task :start => :environment do
+ options = {
+ "-P" => Rails.root.join('log/varnishd.pid'),
+ "-a" => VARNISH_CONFIG[:listen],
+ "-T" => VARNISH_CONFIG[:telnet],
+ "-s" => eval(%Q("#{VARNISH_CONFIG[:storage]}")),
+ "-f" => Rails.root.join('config/varnish.vcl'),
+ }
+
+ params_str = VARNISH_CONFIG[:params].map { |k, v| "-p #{k}=#{v}" }.join(" ")
+ options_str = options.map { |k, v| "#{k} #{v}" }.join(" ")
+
+ cmd = "#{VARNISH_CONFIG[:sbin_path]}/varnishd #{options_str} #{params_str}"
+ puts "** [VARNISH] Booting #{cmd}"
+ `#{cmd}`
+ end
+
+ desc "Stop varnishd daemon using Lacquer's settings"
+ task :stop => :environment do
+ pidfile = Rails.root.join('log/varnishd.pid')
+
+ if pidfile.exist?
+ pid = pidfile.read
+ cmd = "kill #{pid}"
+ puts "** [VARNISH] Killing process with pid #{pid}"
+ `#{cmd}`
+ pidfile.delete
+ else
+ puts "** [VARNISH] pidfile not found"
+ end
+
+ end
+
+ desc "Purge ALL urls from Varnish"
+ task :global_purge => :environment do
+
+ #It WILL timeout, just accept it. Varnish does not have a command prompt.
+ require 'net/telnet'
+ @result = ""
+ begin
+ localhost = Net::Telnet::new("Host" => "localhost", "Port" => 6082, "Timeout" => 5)
+ localhost.cmd("url.purge .*") { |c| @result = c}
+ rescue Exception
+ if @result.include? ("200 0")
+ puts "varnish purged OK."
+ else
+ raise "Varnish not purged."
+ end
+ end
+
+ end
+
+end
View
1 rails/init.rb
@@ -1 +0,0 @@
-require 'lacquer'

0 comments on commit 182b5f5

Please sign in to comment.