jtzemp-poolparty 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +23 -0
- data/LICENSE +22 -0
- data/README +139 -0
- data/Rakefile +109 -0
- data/assets/clouds.png +0 -0
- data/bin/instance +68 -0
- data/bin/pool +83 -0
- data/bin/poolnotify +34 -0
- data/config/cloud_master_takeover +17 -0
- data/config/create_proxy_ami.sh +582 -0
- data/config/haproxy.conf +29 -0
- data/config/heartbeat.conf +8 -0
- data/config/heartbeat_authkeys.conf +2 -0
- data/config/installers/ubuntu_install.sh +77 -0
- data/config/monit.conf +9 -0
- data/config/monit/haproxy.monit.conf +8 -0
- data/config/monit/nginx.monit.conf +0 -0
- data/config/nginx.conf +24 -0
- data/config/reconfigure_instances_script.sh +37 -0
- data/config/sample-config.yml +23 -0
- data/config/scp_instances_script.sh +12 -0
- data/lib/core/array.rb +16 -0
- data/lib/core/exception.rb +9 -0
- data/lib/core/float.rb +13 -0
- data/lib/core/hash.rb +11 -0
- data/lib/core/kernel.rb +12 -0
- data/lib/core/module.rb +22 -0
- data/lib/core/object.rb +21 -0
- data/lib/core/proc.rb +15 -0
- data/lib/core/string.rb +56 -0
- data/lib/core/time.rb +41 -0
- data/lib/helpers/plugin_spec_helper.rb +58 -0
- data/lib/modules/callback.rb +133 -0
- data/lib/modules/ec2_wrapper.rb +108 -0
- data/lib/modules/file_writer.rb +38 -0
- data/lib/modules/safe_instance.rb +31 -0
- data/lib/modules/sprinkle_overrides.rb +27 -0
- data/lib/modules/vlad_override.rb +83 -0
- data/lib/poolparty.rb +131 -0
- data/lib/poolparty/application.rb +199 -0
- data/lib/poolparty/init.rb +6 -0
- data/lib/poolparty/master.rb +492 -0
- data/lib/poolparty/monitors.rb +11 -0
- data/lib/poolparty/monitors/cpu.rb +23 -0
- data/lib/poolparty/monitors/memory.rb +33 -0
- data/lib/poolparty/monitors/web.rb +29 -0
- data/lib/poolparty/optioner.rb +20 -0
- data/lib/poolparty/plugin.rb +78 -0
- data/lib/poolparty/provider.rb +104 -0
- data/lib/poolparty/provider/essential.rb +6 -0
- data/lib/poolparty/provider/git.rb +8 -0
- data/lib/poolparty/provider/haproxy.rb +9 -0
- data/lib/poolparty/provider/heartbeat.rb +6 -0
- data/lib/poolparty/provider/rsync.rb +8 -0
- data/lib/poolparty/provider/ruby.rb +65 -0
- data/lib/poolparty/provider/s3fuse.rb +22 -0
- data/lib/poolparty/remote_instance.rb +250 -0
- data/lib/poolparty/remoter.rb +171 -0
- data/lib/poolparty/remoting.rb +137 -0
- data/lib/poolparty/scheduler.rb +93 -0
- data/lib/poolparty/tasks.rb +47 -0
- data/lib/poolparty/tasks/cloud.rake +57 -0
- data/lib/poolparty/tasks/development.rake +78 -0
- data/lib/poolparty/tasks/ec2.rake +20 -0
- data/lib/poolparty/tasks/instance.rake +63 -0
- data/lib/poolparty/tasks/plugins.rake +30 -0
- data/lib/poolparty/tasks/server.rake +42 -0
- data/lib/poolparty/thread_pool.rb +94 -0
- data/lib/s3/s3_object_store_folders.rb +44 -0
- data/poolparty.gemspec +71 -0
- data/spec/files/describe_response +37 -0
- data/spec/files/multi_describe_response +69 -0
- data/spec/files/remote_desc_response +37 -0
- data/spec/helpers/ec2_mock.rb +57 -0
- data/spec/lib/core/core_spec.rb +26 -0
- data/spec/lib/core/kernel_spec.rb +24 -0
- data/spec/lib/core/string_spec.rb +28 -0
- data/spec/lib/modules/callback_spec.rb +213 -0
- data/spec/lib/modules/file_writer_spec.rb +74 -0
- data/spec/lib/poolparty/application_spec.rb +135 -0
- data/spec/lib/poolparty/ec2_wrapper_spec.rb +110 -0
- data/spec/lib/poolparty/master_spec.rb +479 -0
- data/spec/lib/poolparty/optioner_spec.rb +34 -0
- data/spec/lib/poolparty/plugin_spec.rb +115 -0
- data/spec/lib/poolparty/poolparty_spec.rb +60 -0
- data/spec/lib/poolparty/provider_spec.rb +74 -0
- data/spec/lib/poolparty/remote_instance_spec.rb +178 -0
- data/spec/lib/poolparty/remoter_spec.rb +72 -0
- data/spec/lib/poolparty/remoting_spec.rb +148 -0
- data/spec/lib/poolparty/scheduler_spec.rb +70 -0
- data/spec/monitors/cpu_monitor_spec.rb +39 -0
- data/spec/monitors/memory_spec.rb +51 -0
- data/spec/monitors/misc_monitor_spec.rb +51 -0
- data/spec/monitors/web_spec.rb +40 -0
- data/spec/spec_helper.rb +53 -0
- metadata +312 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
v0.1.2 * Added development tasks for easy setup
|
2
|
+
v0.1.1 * Updated Scheduler to include ThreadPool for threaded safety
|
3
|
+
v0.1.0 * Added poolnotify
|
4
|
+
* Updating gem on github
|
5
|
+
v0.0.9 * Changed configuration style to rsync all files across every instance
|
6
|
+
* Moved configuration back to a configure scrip
|
7
|
+
* Added in vlad configuration
|
8
|
+
* Added plugin ability to install custom software
|
9
|
+
* Updated configuration style
|
10
|
+
* Added cloud_list to pool
|
11
|
+
* Changed listing of the clouds through pool
|
12
|
+
v0.0.8 * Added plugin_manager
|
13
|
+
* Moved remoting to rake remote task (from vlad)
|
14
|
+
* Changed configuration from instance-based to cloud-based
|
15
|
+
v0.0.7 * Updated source
|
16
|
+
v0.0.6 * Plugin support
|
17
|
+
* Cleaned up base
|
18
|
+
* Extensible monitoring
|
19
|
+
v0.0.5 Initial launched release
|
20
|
+
v0.0.4 Rewrite before release - with haproxy, heartbeat, hosts and s3fuse
|
21
|
+
v0.0.3 Rewrite - Cleanup
|
22
|
+
v0.0.2 Rewrite - with web-proxy methods
|
23
|
+
v0.0.1 Initial idea
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2008 <Ari Lerner>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
= poolparty
|
2
|
+
|
3
|
+
http://poolpartyrb.com
|
4
|
+
Ari Lerner
|
5
|
+
CitrusByte
|
6
|
+
http://blog.citrusbyte.com
|
7
|
+
|
8
|
+
== DESCRIPTION:
|
9
|
+
|
10
|
+
poolparty (http://poolpartyrb.com), Ari Lerner (http://blog.xnot.org, http://blog.citrusbyte.com) - poolparty is a framework for maintaining and running auto-scalable applications on Amazon's EC2 cloud. Run entire applications using the EC2 cluster and the unlimited S3 disk. More details to be listed at http://poolpartyrb.com.
|
11
|
+
|
12
|
+
== Basics
|
13
|
+
|
14
|
+
poolparty is written with the intention of being as application-agnostic as possible. It installs only the basic required software to glue the cloud together on the instances as listed below.
|
15
|
+
|
16
|
+
poolparty is easily configuration. In fact, it makes little assumptions about your development environment and allows several options on how to begin configuring the cloud.
|
17
|
+
|
18
|
+
= Development setup
|
19
|
+
|
20
|
+
=== IN THE ENVIRONMENT
|
21
|
+
|
22
|
+
There are 5 values that poolparty reads from the environment, you can set these basic environment variables and leave the rest to the poolparty defaults. Those values are:
|
23
|
+
|
24
|
+
ENV["ACCESS_KEY"] => AWS access key
|
25
|
+
ENV["SECRET_ACCESS_KEY"] => AWS secret access key
|
26
|
+
ENV["CONFIG_FILE"] => Location of your config yaml file (optional)
|
27
|
+
ENV["EC2_HOME"] => EC2 home directory (defaults to ~/.ec2)
|
28
|
+
ENV["KEYPAIR_NAME"] => The keypair used to launch instances
|
29
|
+
|
30
|
+
The structure assumed for the keypair is EC2_HOME/id_rsa-<keypairname>
|
31
|
+
|
32
|
+
=== IN A CONFIG FILE
|
33
|
+
|
34
|
+
poolparty assumes your config directory is set in config/config.yml. However, you can set this in your environment variables and it will read the config file from the environment variable
|
35
|
+
|
36
|
+
=== WITH A RAKE TASK
|
37
|
+
|
38
|
+
poolparty comes with a rake task that can setup your environment for you. Set the environment variables above and run
|
39
|
+
|
40
|
+
rake dev:setup
|
41
|
+
|
42
|
+
This will write a .<KEYPAIR_NAME>_pool_keys into your home directory. Then you can just run
|
43
|
+
|
44
|
+
source ~/.<KEYPAIR_NAME>_pool_keys
|
45
|
+
|
46
|
+
and your environment will be all setup for you everytime you want to work on the cloud
|
47
|
+
|
48
|
+
= Basics
|
49
|
+
|
50
|
+
poolparty can work in two ways to load balance it's traffic. It can either do server-side or client-side load-balancing. Since every instance load balances itself, you can either set the client to grab an instance and send it to that using client-side load balancing (with a js library). Alternatively, you can set the master in dns and reference it when referring to the application.
|
51
|
+
|
52
|
+
Since poolparty makes no assumptions as to what you will be hosting on the application, the world is your oyster when running a cloud. You can set each instance to register with a dynDNS service so that your application has multiple points of entry and can run load-balanced on the fly.
|
53
|
+
|
54
|
+
Every instance will auto-mount the s3 bucket set in the config file (if it is set up) into the /data folder of the instance. This gives each instance access to the same data regardless of the instance. It uses s3fuse and caching through s3fuse in the /tmp directory to work as fast as possible on the local instances.
|
55
|
+
|
56
|
+
The instances all are loaded with the following software:
|
57
|
+
|
58
|
+
* Haproxy - The basic load balancing software
|
59
|
+
* Heartbeat - The failover software
|
60
|
+
* S3Fuse - The mounting software for the s3 bucket
|
61
|
+
* Monit - The maintainer of the services to maintain services
|
62
|
+
|
63
|
+
When an instance is started or brought down, the master is responsible for reloading every instance with the new data on each instance. If the master goes down, the next in succession will take over as the master (using heartbeat) and it will reconfigure the cloud, setting itself as the master and take over the maintenance of the cloud.
|
64
|
+
|
65
|
+
Your cloud is never guaranteed to be maintained, but with more than 1 instance unless you have more than 1 instance up
|
66
|
+
|
67
|
+
Each instance has a /etc/hosts file that has each node listed as the node name listed in the cloud:list (rake task).
|
68
|
+
|
69
|
+
= CloudSpeak - Communicating to your cloud(s)
|
70
|
+
Binaries!
|
71
|
+
Included in poolparty are two binaries to communicate back with your clouds. Those are:
|
72
|
+
|
73
|
+
* pool - operate on your pool. This includes list, start, stop maintain, restart. Check the help with pool -h
|
74
|
+
* instance - operate on a specific instance. This allos you to ssh, scp, reload, install as well. Check the help with: instance -h
|
75
|
+
|
76
|
+
The cloud can be maintained entirely through rake tasks, although there are a few front-ends being developed (one in cocoa).
|
77
|
+
|
78
|
+
It is simple to include these tasks in your Rakefile. Just add the following lines:
|
79
|
+
|
80
|
+
require "poolparty"
|
81
|
+
PoolParty.include_cloud_tasks # or PoolParty.tasks or PoolParty.include_tasks
|
82
|
+
|
83
|
+
All the cloud rake tasks are in the cloud namespace and can be viewed with:
|
84
|
+
|
85
|
+
rake -T cloud
|
86
|
+
|
87
|
+
The instance rake tasks are in the instance namespace and can be listed with:
|
88
|
+
|
89
|
+
rake -T instance
|
90
|
+
|
91
|
+
For more help, check http://poolpartyrb.com
|
92
|
+
|
93
|
+
== REQUIREMENTS:
|
94
|
+
|
95
|
+
* aws/s3
|
96
|
+
* aska
|
97
|
+
* EC2
|
98
|
+
|
99
|
+
== INSTALL:
|
100
|
+
|
101
|
+
gem install auser-poolparty
|
102
|
+
|
103
|
+
== ROADMAP
|
104
|
+
|
105
|
+
v0.1.4 - Add documentation
|
106
|
+
v0.1.5 - Add AMI bundling tasks
|
107
|
+
|
108
|
+
== THANKS
|
109
|
+
|
110
|
+
Ron Evans, http://deadprogrammersociety.blogspot.com/ for his enthusiasm
|
111
|
+
Tim Goh, http://citrusbyte.com for sanity checks and thoughts
|
112
|
+
PJ Cabrera, http://pjtrix.com for excitement, thoughts and contribution
|
113
|
+
Blake Mizerany, http://sinatrarb.com/, for his support and ideas
|
114
|
+
Nicolás 'Foca' Sanguinetti, http://nicolassanguinetti.info/
|
115
|
+
|
116
|
+
== LICENSE:
|
117
|
+
|
118
|
+
(The MIT License)
|
119
|
+
|
120
|
+
Copyright (c) 2008 Ari Lerner. CitrusByte
|
121
|
+
|
122
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
123
|
+
a copy of this software and associated documentation files (the
|
124
|
+
'Software'), to deal in the Software without restriction, including
|
125
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
126
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
127
|
+
permit persons to whom the Software is furnished to do so, subject to
|
128
|
+
the following conditions:
|
129
|
+
|
130
|
+
The above copyright notice and this permission notice shall be
|
131
|
+
included in all copies or substantial portions of the Software.
|
132
|
+
|
133
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
134
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
135
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
136
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
137
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
138
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
139
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "./lib/poolparty"
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'echoe'
|
6
|
+
|
7
|
+
Echoe.new("poolparty") do |s|
|
8
|
+
s.author = ["Ari Lerner"]
|
9
|
+
s.rubyforge_name = "poolparty"
|
10
|
+
s.email = "ari.lerner@citrusbyte.com"
|
11
|
+
s.summary = "Run your entire application off EC2, managed and auto-scaling"
|
12
|
+
s.url = "http://poolpartyrb.com"
|
13
|
+
s.dependencies = ["aws-s3", "amazon-ec2", "auser-aska", "git", "sprinkle", "SystemTimer", "open4"]
|
14
|
+
s.install_message = %q{
|
15
|
+
|
16
|
+
Get ready to jump in the pool, you just installed PoolParty!
|
17
|
+
|
18
|
+
Please check out the documentation for any questions or check out the google groups at
|
19
|
+
http://groups.google.com/group/poolpartyrb
|
20
|
+
|
21
|
+
Don't forget to check out the plugin tutorial @ http://poolpartyrb.com for extending PoolParty!
|
22
|
+
|
23
|
+
For more information, check http://poolpartyrb.com
|
24
|
+
On IRC:
|
25
|
+
irc.freenode.net
|
26
|
+
#poolpartyrb
|
27
|
+
|
28
|
+
*** Ari Lerner @ <ari.lerner@citrusbyte.com> ***
|
29
|
+
}
|
30
|
+
end
|
31
|
+
rescue LoadError => boom
|
32
|
+
puts "You are missing a dependency required for meta-operations on this gem."
|
33
|
+
end
|
34
|
+
|
35
|
+
PoolParty.include_tasks
|
36
|
+
|
37
|
+
# add spec tasks, if you have rspec installed
|
38
|
+
begin
|
39
|
+
require 'spec/rake/spectask'
|
40
|
+
|
41
|
+
Spec::Rake::SpecTask.new("spec") do |t|
|
42
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
43
|
+
t.spec_opts = ['--color']
|
44
|
+
end
|
45
|
+
|
46
|
+
Spec::Rake::SpecTask.new("rcov_spec") do |t|
|
47
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
48
|
+
t.spec_opts = ['--color']
|
49
|
+
t.rcov = true
|
50
|
+
t.rcov_opts = ['--exclude', '^spec,/gems/']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
namespace(:pkg) do
|
55
|
+
## Rake task to create/update a .manifest file in your project, as well as update *.gemspec
|
56
|
+
desc %{Update ".manifest" with the latest list of project filenames. Respect\
|
57
|
+
.gitignore by excluding everything that git ignores. Update `files` and\
|
58
|
+
`test_files` arrays in "*.gemspec" file if it's present.}
|
59
|
+
task :manifest do
|
60
|
+
list = Dir['**/*'].sort
|
61
|
+
spec_file = Dir['*.gemspec'].first
|
62
|
+
list -= [spec_file] if spec_file
|
63
|
+
|
64
|
+
File.read('.gitignore').each_line do |glob|
|
65
|
+
glob = glob.chomp.sub(/^\//, '')
|
66
|
+
list -= Dir[glob]
|
67
|
+
list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
|
68
|
+
puts "excluding #{glob}"
|
69
|
+
end
|
70
|
+
|
71
|
+
if spec_file
|
72
|
+
spec = File.read spec_file
|
73
|
+
spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
|
74
|
+
assignment = $1
|
75
|
+
bunch = $2 ? list.grep(/^test\//) : list
|
76
|
+
'%s%%w(%s)' % [assignment, bunch.join(' ')]
|
77
|
+
end
|
78
|
+
|
79
|
+
File.open(spec_file, 'w') {|f| f << spec }
|
80
|
+
end
|
81
|
+
File.open('Manifest', 'w') {|f| f << list.join("\n") }
|
82
|
+
end
|
83
|
+
desc "Build gemspec for github"
|
84
|
+
task :gemspec => [:manifest, :gem] do
|
85
|
+
require "yaml"
|
86
|
+
data = YAML.load(open("poolparty.gemspec").read).to_ruby
|
87
|
+
File.open("poolparty.gemspec", "w+") {|f| f << data }
|
88
|
+
end
|
89
|
+
desc "Update gemspec with the time"
|
90
|
+
task :gemspec_update => :gemspec do
|
91
|
+
data = open("poolparty.gemspec").read
|
92
|
+
str = "Updated at #{Time.now.strftime("%I:%M%p, %D")}"
|
93
|
+
|
94
|
+
if data.scan(/Updated at/).empty?
|
95
|
+
data = data.gsub(/you just installed PoolParty\!/, '\0'+" (#{str})")
|
96
|
+
end
|
97
|
+
|
98
|
+
File.open("poolparty.gemspec", "w+") {|f| f << data }
|
99
|
+
end
|
100
|
+
desc "Get ready to release the gem"
|
101
|
+
task :prerelease => [:gemspec_update] do
|
102
|
+
`git add .`
|
103
|
+
`git ci -a -m "Updated gemspec for github"`
|
104
|
+
end
|
105
|
+
desc "Release them gem to the gem server"
|
106
|
+
task :release => [:prerelease] do
|
107
|
+
`git push origin master`
|
108
|
+
end
|
109
|
+
end
|
data/assets/clouds.png
ADDED
Binary file
|
data/bin/instance
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'optparse'
|
4
|
+
require 'poolparty'
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
# Set defaults
|
8
|
+
commandables = %w(ssh cmd scp restart start stop install start_maintain stop_maintain)
|
9
|
+
options = PoolParty.options(:optsparse =>
|
10
|
+
{ :banner => <<-EOU
|
11
|
+
Usage: instance [OPTIONS] { #{commandables.join(" | ")} }
|
12
|
+
-----------------------------------------------------------------
|
13
|
+
EOU
|
14
|
+
})
|
15
|
+
|
16
|
+
PoolParty.load_app
|
17
|
+
|
18
|
+
master = PoolParty::Master.new
|
19
|
+
list = PoolParty::Optioner.parse(ARGV.dup, %w(-v --verbose))
|
20
|
+
num = list.reject {|a| commandables.include?(a) }.pop
|
21
|
+
|
22
|
+
instance = master.get_node( num || 0 )
|
23
|
+
|
24
|
+
unless instance
|
25
|
+
puts "Cloud is not running"
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
|
29
|
+
list.each do |cmd|
|
30
|
+
case cmd
|
31
|
+
when "ssh"
|
32
|
+
PoolParty.message "Ssh'ing into #{instance.ip}"
|
33
|
+
instance.ssh
|
34
|
+
when "cmd"
|
35
|
+
PoolParty.message "Executing #{instance_options[:cmd]} on #{instance.ip}"
|
36
|
+
instance.ssh list.shift
|
37
|
+
when "scp"
|
38
|
+
list.shift
|
39
|
+
src, dest = list.shift, (list.shift || "~")
|
40
|
+
PoolParty.message "Scp'ing #{src} to #{dest}"
|
41
|
+
instance.scp src, (dest || "~")
|
42
|
+
when "restart"
|
43
|
+
PoolParty.message "Restarting services"
|
44
|
+
instance.restart_with_monit
|
45
|
+
when "start"
|
46
|
+
PoolParty.message "Starting services"
|
47
|
+
instance.start_with_monit
|
48
|
+
when "stop"
|
49
|
+
PoolParty.message "Stopping services"
|
50
|
+
instance.stop_with_monit
|
51
|
+
when "install"
|
52
|
+
PoolParty.message "Installing services"
|
53
|
+
instance.install
|
54
|
+
when "start_maintain"
|
55
|
+
PoolParty.message "Running heartbeat failover service"
|
56
|
+
pid = Master.run_thread_loop(:daemonize => true) do
|
57
|
+
instance.become_master if instance.is_not_master_and_master_is_not_running?
|
58
|
+
end
|
59
|
+
File.open(Application.maintain_pid_path) {|f| f.write(pid)}
|
60
|
+
when "stop_maintain"
|
61
|
+
PoolParty.message "Stopping heartbeat failover service"
|
62
|
+
pid = open(Application.maintain_pid_path).read
|
63
|
+
`kill -9 #{pid}`
|
64
|
+
FileUtils.rm Application.maintain_pid_path # Check this
|
65
|
+
else
|
66
|
+
puts master.list
|
67
|
+
end
|
68
|
+
end
|
data/bin/pool
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
$:.unshift(File.join(File.dirname(__FILE__)))
|
3
|
+
require 'poolparty'
|
4
|
+
|
5
|
+
def display_config_data
|
6
|
+
PoolParty.message <<-EOM
|
7
|
+
PoolParty cloud: #{PoolParty::Application.app_name ? "#{PoolParty::Application.app_name} " : "" }
|
8
|
+
On #{PoolParty::Application.ami}
|
9
|
+
Minimum instances: #{PoolParty::Application.minimum_instances}
|
10
|
+
Maximum instances: #{PoolParty::Application.maximum_instances}
|
11
|
+
Polling every: #{PoolParty::Application.polling_time}
|
12
|
+
Keypair: #{PoolParty::Application.keypair}
|
13
|
+
Access key: #{PoolParty::Application.access_key}
|
14
|
+
size: #{PoolParty::Application.size}
|
15
|
+
Monitors available:
|
16
|
+
--------------
|
17
|
+
#{PoolParty.registered_monitors.collect {|a| " #{a}"}}
|
18
|
+
|
19
|
+
Plugins:
|
20
|
+
--------------
|
21
|
+
#{Dir["#{PoolParty::Application.plugin_dir}/*"].collect {|a| " #{File.basename(a)}"}.join("\n")}
|
22
|
+
|
23
|
+
EOM
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set defaults
|
27
|
+
options = PoolParty.options(:optsparse =>
|
28
|
+
{:banner => <<-EOU
|
29
|
+
Usage: pool [OPTIONS] {start | stop | list | clouds_list | maintain | restart | install | configure | grow | shrink | ssh | switch}
|
30
|
+
-----------------------------------------------------------------
|
31
|
+
EOU
|
32
|
+
})
|
33
|
+
|
34
|
+
PoolParty.load_app
|
35
|
+
master = PoolParty::Master.new
|
36
|
+
list = PoolParty::Optioner.parse(ARGV.dup, %w(-v))
|
37
|
+
|
38
|
+
display_config_data
|
39
|
+
|
40
|
+
list.each do |cmd|
|
41
|
+
case cmd
|
42
|
+
when "start"
|
43
|
+
master.start_cloud!
|
44
|
+
when "show"
|
45
|
+
display_config_data
|
46
|
+
when "grow"
|
47
|
+
master.grow_by
|
48
|
+
when "shrink"
|
49
|
+
master.shrink_by
|
50
|
+
when "install"
|
51
|
+
master.install_cloud(true)
|
52
|
+
when "configure"
|
53
|
+
master.setup_cloud
|
54
|
+
when "ssh"
|
55
|
+
list.shift
|
56
|
+
PoolParty.message "Running #{list} on the cloud"
|
57
|
+
master.ssh list.shift
|
58
|
+
when "stop"
|
59
|
+
PoolParty.message "Stopping cloud"
|
60
|
+
master.request_termination_of_all_instances
|
61
|
+
when "list"
|
62
|
+
puts master.list
|
63
|
+
when "size"
|
64
|
+
puts master.nodes.size
|
65
|
+
when "clouds_list"
|
66
|
+
puts master.clouds_list
|
67
|
+
when "maintain"
|
68
|
+
PoolParty.message "Maintaining cloud"
|
69
|
+
master.start_monitor!
|
70
|
+
when "restart"
|
71
|
+
PoolParty.message "Restarting cloud"
|
72
|
+
master.request_termination_of_all_instances
|
73
|
+
master.start_cloud!
|
74
|
+
when "switch"
|
75
|
+
list.shift
|
76
|
+
context = list.shift
|
77
|
+
keyfilename = ".#{context}_pool_keys"
|
78
|
+
PoolParty.message "switching cloud to #{context}"
|
79
|
+
context ? Kernel.system("source $HOME/#{keyfilename}") : puts("You must supply a context to switch to")
|
80
|
+
else
|
81
|
+
puts master.list
|
82
|
+
end
|
83
|
+
end
|