-
Notifications
You must be signed in to change notification settings - Fork 2
/
purge.rb
executable file
·46 lines (38 loc) · 923 Bytes
/
purge.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
require 'nesta/env'
Nesta::Env.root = ::File.expand_path('.', ::File.dirname(__FILE__))
require 'nesta/app'
require 'socket'
varnish = '127.0.0.1'
if ARGV[0] then
varnish = ARGV[0]
end
def purge(path, host, port = 80)
# s = TCPSocket.new host, port
#
# s.puts 'PURGE ' + path + ' HTTP/1.1'
# s.puts 'Host: openstreetmap.se'
# s.puts ''
#
# while line = s.gets
# puts line
# if line.strip.empty? then
# break
# end
# end
#
# s.close
cmd = "curl -i -X PURGE -H 'Host: openstreetmap.se' http://127.0.0.1%s" % path
system(cmd)
cmd = "curl -i -X PURGE -H 'Host: openstreetmap.se' -k https://127.0.0.1%s" % path
system(cmd)
end
Nesta::Page.find_all.each do |page|
if page.last_modified > Time.now - 3600*48 or true then
puts 'Purging /' + page.path
purge('/' + page.path, varnish)
end
end