ece_prewarmer 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/ece-prewarmer +68 -0
- data/bin/setup +7 -0
- data/ece_prewarmer.gemspec +30 -0
- data/lib/ece_prewarmer.rb +61 -0
- data/lib/ece_prewarmer/version.rb +3 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a9117e52be8f65c868135d41cf76ae16ff2d966
|
4
|
+
data.tar.gz: 9fadebec9efcc605a8002cc36977a78b32625a1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7cca009932ad63717b2632fb10cbac7b9cbbc9cc557c9e7713b88eb53f672d9e7543e1f8a234ab068587dc7aca24e150c5ab37e0e8c4ade6ff4b3ca76582ed99
|
7
|
+
data.tar.gz: 9e7e8632eb438f97961ae36bfb99630e525b14d2cbe74bf28bfc7c4197fb558b3ca345fd1a094675cfb66491d6dcd4d92026d0ab11a009e7883fa18926ff18cf
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Patricio Bruna
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# EcePrewarmer
|
2
|
+
|
3
|
+
Script para pre-calentar servidores escenic.
|
4
|
+
|
5
|
+
Se usa mas o menos así:
|
6
|
+
|
7
|
+
```bash
|
8
|
+
[host ]$ screen
|
9
|
+
[host ]$ unset http_proxy
|
10
|
+
[host ]$ ece-prewarmer -s www.24horas.cl -i 10.132.17.114 -p 8080 -v -t 8
|
11
|
+
```
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ece_prewarmer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```bash
|
22
|
+
[host]$ ece-prewarmer --help
|
23
|
+
Usage: ece-prewarmer --site [www.24horas.cl] --host [next-presentation-1.tvn.org]
|
24
|
+
-s, --site=SITE El sitio web
|
25
|
+
-i, --ipaddress=HOST IP Address del servidor Presentation
|
26
|
+
-p, --port=PORT El puerto destino, 80 por defecto
|
27
|
+
-d, --depth=DEPTH Limite de links a seguir
|
28
|
+
-t, --threads=THREADS Procesos a lanzar
|
29
|
+
-V, --version Version
|
30
|
+
-v, --verbose Mas debug
|
31
|
+
-h, --help Esta ayuda
|
32
|
+
```
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
+
|
38
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( https://github.com/[my-github-username]/ece_prewarmer/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ece_prewarmer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/ece-prewarmer
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ece_prewarmer'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
# Parsing options
|
8
|
+
ARGV << '-h' if ARGV.empty?
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
optparse = OptionParser.new do |opts|
|
13
|
+
opts.banner = 'Usage: ece-prewarmer --site [www.24horas.cl] --host [next-presentation-1.tvn.org]'
|
14
|
+
|
15
|
+
opts.on('-sSITE', '--site=SITE', 'El sitio web') do |o|
|
16
|
+
options[:website] = o
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on('-i', '--ipaddress=HOST', 'IP Address del servidor Presentation') do |o|
|
20
|
+
options[:host] = o
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on('-pPORT', '--port=PORT', 'El puerto destino, 80 por defecto') do |o|
|
24
|
+
options[:port] = o.nil? ? nil : o.to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on('-dDEPTH', '--depth=DEPTH', 'Limite de links a seguir') do |o|
|
28
|
+
options[:depth_limit] = o.nil? ? nil : o.to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on('-tTHREADS', '--threads=THREADS', 'Procesos a lanzar') do |o|
|
32
|
+
options[:threads] = o.nil? ? nil : o.to_i
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on('-V', '--version', 'Version') do |o|
|
36
|
+
puts EcePrewarmer::VERSION
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on('-v', '--verbose', 'Mas debug') do |o|
|
41
|
+
options[:verbose] = true
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on('-h', '--help', 'Esta ayuda') do
|
45
|
+
puts opts
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
optparse.parse!
|
51
|
+
opts = {}
|
52
|
+
host = options[:host]
|
53
|
+
website = options[:website]
|
54
|
+
opts[:verbose] = options[:verbose]
|
55
|
+
opts[:port] = options[:port]
|
56
|
+
opts[:threads] = options[:threads]
|
57
|
+
opts[:depth_limit] = options[:depth_limit]
|
58
|
+
|
59
|
+
results = EcePrewarmer.prewarm(host, website, opts)
|
60
|
+
|
61
|
+
puts "Paginas visitadas: #{results.size}\n"
|
62
|
+
|
63
|
+
|
64
|
+
BEGIN {
|
65
|
+
at_exit {
|
66
|
+
EcePrewarmer.remove_host_alias(website)
|
67
|
+
}
|
68
|
+
}
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ece_prewarmer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ece_prewarmer"
|
8
|
+
spec.version = EcePrewarmer::VERSION
|
9
|
+
spec.authors = ["Patricio Bruna"]
|
10
|
+
spec.email = ["pbruna@itlinux.cl"]
|
11
|
+
|
12
|
+
spec.summary = 'Script para pre-calentar servidores escenic'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/pbruna/ece_prewarmer"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'anemone', '~> 0.7'
|
23
|
+
spec.add_dependency 'hosts', '~> 0.1'
|
24
|
+
spec.add_dependency "bundler", "~> 1.9"
|
25
|
+
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "guard", "~> 2.12"
|
28
|
+
spec.add_development_dependency "guard-minitest", "~> 2.4"
|
29
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.0"
|
30
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'hosts'
|
2
|
+
require 'anemone'
|
3
|
+
require 'uri'
|
4
|
+
require 'ece_prewarmer/version'
|
5
|
+
|
6
|
+
module EcePrewarmer
|
7
|
+
|
8
|
+
def self.add_host_alias(ip, host_alias, file = nil)
|
9
|
+
file ||= '/etc/hosts'
|
10
|
+
hosts = Hosts::File.read(file)
|
11
|
+
hosts.elements << Hosts::Entry.new(ip, host_alias)
|
12
|
+
hosts.invalidate_cache!
|
13
|
+
hosts.write
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.remove_host_alias(hostname, file = nil)
|
17
|
+
file ||= '/etc/hosts'
|
18
|
+
hosts = Hosts::File.read(file)
|
19
|
+
to_delete = hosts.elements.each_with_index.map {|e,i| i if e.name == hostname }.compact
|
20
|
+
to_delete.each { |i| hosts.elements[i] = nil }
|
21
|
+
hosts.elements.compact!
|
22
|
+
hosts.write
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.prewarm(host, website, opts = {})
|
26
|
+
opts = parse_opts opts
|
27
|
+
url = "http://#{website}:#{opts[:port]}/"
|
28
|
+
add_host_alias(host, website, opts[:hostfile])
|
29
|
+
results = crawl(url, opts[:port], opts[:verbose], opts[:threads], opts[:depth_limit])
|
30
|
+
remove_host_alias(website, opts[:hostfile])
|
31
|
+
results
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.crawl(url, port, verbose, threads, depth)
|
35
|
+
result = []
|
36
|
+
Anemone.crawl(url, verbose: verbose, threads: threads, depth_limit: depth) do |anemone|
|
37
|
+
links = []
|
38
|
+
anemone.on_every_page do |page|
|
39
|
+
links.push page.url
|
40
|
+
new_links = page.links.each do |l|
|
41
|
+
uri = URI l
|
42
|
+
uri.port = port
|
43
|
+
uri.to_s
|
44
|
+
end
|
45
|
+
anemone.focus_crawl { new_links }
|
46
|
+
end
|
47
|
+
anemone.after_crawl { result = links }
|
48
|
+
end
|
49
|
+
result
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.parse_opts(opts)
|
53
|
+
opts[:threads] ||= 4
|
54
|
+
opts[:hostfile] ||= nil
|
55
|
+
opts[:verbose] ||= false
|
56
|
+
opts[:port] ||= 80
|
57
|
+
opts[:depth_limit] ||= false
|
58
|
+
opts
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ece_prewarmer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patricio Bruna
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: anemone
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hosts
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.9'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.12'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-reporters
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
111
|
+
description: Script para pre-calentar servidores escenic
|
112
|
+
email:
|
113
|
+
- pbruna@itlinux.cl
|
114
|
+
executables:
|
115
|
+
- console
|
116
|
+
- ece-prewarmer
|
117
|
+
- setup
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- .gitignore
|
122
|
+
- .travis.yml
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/ece-prewarmer
|
129
|
+
- bin/setup
|
130
|
+
- ece_prewarmer.gemspec
|
131
|
+
- lib/ece_prewarmer.rb
|
132
|
+
- lib/ece_prewarmer/version.rb
|
133
|
+
homepage: https://github.com/pbruna/ece_prewarmer
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.4.6
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Script para pre-calentar servidores escenic
|
157
|
+
test_files: []
|
158
|
+
has_rdoc:
|