ece_prewarmer 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/bin/ece-prewarmer +25 -1
- data/lib/ece_prewarmer/version.rb +1 -1
- data/lib/ece_prewarmer.rb +7 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60b9d13d4482a9a9310981a92a63c716807c1c93
|
4
|
+
data.tar.gz: 61bc0497385142dff1d5bb8ba19f7fa487046e86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b721be666c2ae0754ce3d2661cac1a96e9d5590fee39fba3c3577b9c4e786298a375bc722364c8d8c2dfb857593d7196eea9ac796a3396e08fcde63ef13c0764
|
7
|
+
data.tar.gz: 74ffb3a1ced07098ede80272174fca72fb11fde435e5920c44659fe15cca00470bd6d5f09ab52d1189aca5c6b8e6322eec482f9c654d8838f287bd29731443e2
|
data/README.md
CHANGED
@@ -8,6 +8,14 @@ Se usa mas o menos así:
|
|
8
8
|
[host ]$ screen
|
9
9
|
[host ]$ unset http_proxy
|
10
10
|
[host ]$ ece-prewarmer -s www.24horas.cl -i 10.132.17.114 -p 8080 -v -t 8
|
11
|
+
http://www.24horas.cl:8080/ Queue: 0
|
12
|
+
http://www.24horas.cl:8080/envivo/ Queue: 104
|
13
|
+
http://www.24horas.cl:8080/internacional/ Queue: 103
|
14
|
+
http://www.24horas.cl:8080/nacional/ Queue: 137
|
15
|
+
http://www.24horas.cl:8080/videos/ Queue: 169
|
16
|
+
http://www.24horas.cl:8080/galerias/ Queue: 168
|
17
|
+
http://www.24horas.cl:8080/envivo/?articleId=221352 Queue: 167
|
18
|
+
http://www.24horas.cl:8080/envivo/?articleId=110846 Queue: 166
|
11
19
|
```
|
12
20
|
|
13
21
|
## Installation
|
data/bin/ece-prewarmer
CHANGED
@@ -28,6 +28,10 @@ optparse = OptionParser.new do |opts|
|
|
28
28
|
options[:depth_limit] = o.nil? ? nil : o.to_i
|
29
29
|
end
|
30
30
|
|
31
|
+
opts.on('-dUSERAGENT', '--depth=USER-AGENT', 'USER-AGENT a usar') do |o|
|
32
|
+
options[:user_agent] = o.nil? ? nil : o.to_i
|
33
|
+
end
|
34
|
+
|
31
35
|
opts.on('-tTHREADS', '--threads=THREADS', 'Procesos a lanzar') do |o|
|
32
36
|
options[:threads] = o.nil? ? nil : o.to_i
|
33
37
|
end
|
@@ -55,12 +59,32 @@ opts[:verbose] = options[:verbose]
|
|
55
59
|
opts[:port] = options[:port]
|
56
60
|
opts[:threads] = options[:threads]
|
57
61
|
opts[:depth_limit] = options[:depth_limit]
|
62
|
+
opts[:user_agent] = options[:user_agent]
|
63
|
+
|
64
|
+
def shutdown
|
65
|
+
Thread.list.each do |thread|
|
66
|
+
thread.exit unless thread == Thread.current
|
67
|
+
end
|
68
|
+
puts "Eliminando entrada de hosts file"
|
69
|
+
FileUtils.cp "/tmp/hosts", '/etc/hosts'
|
70
|
+
end
|
71
|
+
|
72
|
+
# Trap ^C
|
73
|
+
Signal.trap("INT") {
|
74
|
+
shutdown
|
75
|
+
exit
|
76
|
+
}
|
77
|
+
|
78
|
+
# Trap `Kill `
|
79
|
+
Signal.trap("TERM") {
|
80
|
+
shutdown
|
81
|
+
exit
|
82
|
+
}
|
58
83
|
|
59
84
|
results = EcePrewarmer.prewarm(host, website, opts)
|
60
85
|
|
61
86
|
puts "Paginas visitadas: #{results.size}\n"
|
62
87
|
|
63
|
-
|
64
88
|
BEGIN {
|
65
89
|
at_exit {
|
66
90
|
EcePrewarmer.remove_host_alias(website)
|
data/lib/ece_prewarmer.rb
CHANGED
@@ -7,6 +7,7 @@ module EcePrewarmer
|
|
7
7
|
|
8
8
|
def self.add_host_alias(ip, host_alias, file = nil)
|
9
9
|
file ||= '/etc/hosts'
|
10
|
+
FileUtils.cp('/etc/hosts', '/tmp/hosts') if file == '/etc/hosts'
|
10
11
|
hosts = Hosts::File.read(file)
|
11
12
|
hosts.elements << Hosts::Entry.new(ip, host_alias)
|
12
13
|
hosts.invalidate_cache!
|
@@ -22,6 +23,7 @@ module EcePrewarmer
|
|
22
23
|
end
|
23
24
|
to_delete.compact.each { |i| hosts.elements[i] = nil }
|
24
25
|
hosts.elements.compact!
|
26
|
+
hosts.invalidate_cache!
|
25
27
|
hosts.write
|
26
28
|
end
|
27
29
|
|
@@ -29,14 +31,14 @@ module EcePrewarmer
|
|
29
31
|
opts = parse_opts opts
|
30
32
|
url = "http://#{website}:#{opts[:port]}/"
|
31
33
|
add_host_alias(host, website, opts[:hostfile])
|
32
|
-
results = crawl(url, opts[:port], opts[:verbose], opts[:threads], opts[:depth_limit])
|
34
|
+
results = crawl(url, opts[:port], opts[:verbose], opts[:threads], opts[:depth_limit], opts[:user_agent])
|
33
35
|
remove_host_alias(website, opts[:hostfile])
|
34
36
|
results
|
35
37
|
end
|
36
38
|
|
37
|
-
def self.crawl(url, port, verbose, threads, depth)
|
39
|
+
def self.crawl(url, port, verbose, threads, depth, user_agent)
|
38
40
|
result = []
|
39
|
-
Anemone.crawl(url, verbose: verbose, threads: threads, depth_limit: depth) do |anemone|
|
41
|
+
Anemone.crawl(url, verbose: verbose, threads: threads, depth_limit: depth, user_agent: user_agent) do |anemone|
|
40
42
|
links = []
|
41
43
|
anemone.on_every_page do |page|
|
42
44
|
links.push page.url
|
@@ -58,6 +60,8 @@ module EcePrewarmer
|
|
58
60
|
opts[:verbose] ||= false
|
59
61
|
opts[:port] ||= 80
|
60
62
|
opts[:depth_limit] ||= false
|
63
|
+
# Chrome by default
|
64
|
+
opts[:user_agent] ||= "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36"
|
61
65
|
opts
|
62
66
|
end
|
63
67
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ece_prewarmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricio Bruna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anemone
|