idle_whacker 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. data/Gemfile +3 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +36 -0
  4. data/Rakefile +23 -0
  5. data/whacker.rb +54 -0
  6. metadata +99 -0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 AKSHAY RAWAT
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ #Idle Whacker
2
+
3
+ ## What the?
4
+
5
+ Idle whacker polls a given url periodically so that the app server never goes to sleep.
6
+
7
+ ## How the?
8
+
9
+ Idle whacker installs a crontab entry on a given (host) machine which then uses `ab` (apache-bench) to generate traffic to a given URL periodically.
10
+
11
+ ## Installation
12
+
13
+ Idle whacker depends on `ab` being available on the command line. `ab` (apache-bench) can be installed via `apt-get install apache2-utils` - this is a really small util, with libreadline at its only dependency.
14
+
15
+ gem install idle_whacker
16
+
17
+ ## Usage
18
+
19
+ > rake -T
20
+ rake idle_whacker:install # Install the whack
21
+ rake idle_whacker:remove # Removes all whacks
22
+ rake idle_whacker:show # Shows all the whacking installed
23
+ rake idle_whacker:test # Test a sample whack
24
+
25
+ _A sample session of installing a whack_
26
+
27
+ > rake idle_whacker:install
28
+ URL to whack, eg(http://www.foobar-server.com/lazy_boy.html): http://www.nest.com/about/ #URL to poll for.
29
+ Whacker install host eg(www.foobar-server.com): www.whacker.com #Machine where the crontab will be installed
30
+ Username: deployer #Login to the above install host
31
+ Password (Leave this blank if ssh keys are setup):
32
+
33
+ Installing crontab entry..
34
+ */5 * * * * echo '[idle_whacking]' && ab -c 5 -n 25 http://www.nest.com/about/
35
+
36
+ Done.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require './whacker'
2
+
3
+ namespace :idle_whacker do
4
+ desc "Test a sample whack"
5
+ task :test do
6
+ Whacker.new.test
7
+ end
8
+
9
+ desc "Install the whack"
10
+ task :install do
11
+ Whacker.new.install
12
+ end
13
+
14
+ desc "Removes all whacks"
15
+ task :remove do
16
+ Whacker.new.remove
17
+ end
18
+
19
+ desc "Shows all the whacking installed"
20
+ task :show do
21
+ Whacker.new.show
22
+ end
23
+ end
data/whacker.rb ADDED
@@ -0,0 +1,54 @@
1
+ require "highline/import"
2
+ require 'net/ssh'
3
+
4
+ class Whacker
5
+
6
+ def test
7
+ url_to_whack = ask("URL to whack, eg(http://www.foobar-server.com/lazy_boy.html): ") {|q| q.validate = /\w+/ }
8
+ run_remote do |ssh|
9
+ command = "#{ab(url_to_whack)}"
10
+ puts ssh.exec! command
11
+ end
12
+ end
13
+
14
+ def install
15
+ url_to_whack = ask("URL to whack, eg(http://www.foobar-server.com/lazy_boy.html): ") {|q| q.validate = /\w+/ }
16
+ cron_entry = "*/5 * * * * echo '[idle_whacking]' && #{ab(url_to_whack)}"
17
+ run_remote do |ssh|
18
+ puts "Installing crontab entry.."
19
+ puts cron_entry
20
+ puts ssh.exec! "(crontab -l; echo '#{cron_entry}') | crontab -"
21
+ puts "Done."
22
+ end
23
+ end
24
+
25
+ def show
26
+ run_remote do |ssh|
27
+ puts "Crontab entries for idle whacking:"
28
+ puts ssh.exec! "crontab -l | grep 'idle_whacking'"
29
+ end
30
+ end
31
+
32
+ def remove
33
+ run_remote do |ssh|
34
+ puts ssh.exec! "(crontab -l | grep -v 'idle_whacking') | crontab -"
35
+ puts "Removed all idle whacking"
36
+ end
37
+ end
38
+
39
+ def run_remote
40
+ host = ask("Whacker install host eg(www.foobar-server.com): ") {|q| q.validate = /\w+/ }
41
+ username = ask("Username: ") {|q| q.validate = /\w+/ }
42
+ password = ask("Password (Leave this blank if ssh keys are setup): ") { |q| q.echo = '*' }
43
+ Net::SSH.start( host , username, password: password) do |ssh|
44
+ yield ssh
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def ab url
51
+ "ab -c 5 -n 25 #{url}"
52
+ end
53
+
54
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: idle_whacker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Akshay Rawat
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: net-ssh
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: highline
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Idle whacker polls a given url periodically so that the app server never
63
+ goes to sleep.
64
+ email:
65
+ - projects@akshay.cc
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - MIT-LICENSE
71
+ - Rakefile
72
+ - Gemfile
73
+ - README.md
74
+ - whacker.rb
75
+ homepage: http://portfolio.akshay.cc/idle_whacker/
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.23
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Whack those urls so that they never sleep
99
+ test_files: []