poolparty 0.0.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +25 -0
- data/License.txt +20 -0
- data/Manifest.txt +203 -0
- data/PostInstall.txt +18 -0
- data/README.txt +21 -82
- data/Rakefile +25 -18
- data/bin/cloud +31 -0
- data/bin/cloud-add-keypair +23 -0
- data/bin/cloud-configure +31 -0
- data/bin/cloud-contract +27 -0
- data/bin/cloud-expand +27 -0
- data/bin/cloud-list +32 -0
- data/bin/cloud-maintain +36 -0
- data/bin/cloud-osxcopy +22 -0
- data/bin/cloud-provision +31 -0
- data/bin/cloud-refresh +26 -0
- data/bin/cloud-ssh +18 -0
- data/bin/cloud-start +32 -0
- data/bin/cloud-terminate +23 -0
- data/bin/pool +25 -27
- data/bin/pool-console +12 -0
- data/bin/pool-describe +9 -0
- data/bin/pool-list +28 -0
- data/bin/pool-provision +34 -0
- data/bin/pool-spec +17 -0
- data/bin/pool-start +32 -0
- data/bin/pool-start-monitor +1 -0
- data/config/hoe.rb +115 -0
- data/config/requirements.rb +15 -0
- data/examples/basic.rb +20 -0
- data/examples/plugin_without_plugin_directory.rb +13 -0
- data/examples/poolparty.rb +12 -0
- data/examples/with_apache_plugin.rb +22 -0
- data/generators/poolspec/USAGE +5 -0
- data/generators/poolspec/poolspec_generator.rb +65 -0
- data/generators/poolspec/templates/pool_spec_template.erb +9 -0
- data/lib/erlang/eb_server.erl +27 -0
- data/lib/poolparty.rb +56 -0
- data/lib/poolparty/base_packages/haproxy.rb +42 -0
- data/lib/poolparty/base_packages/heartbeat.rb +45 -0
- data/lib/poolparty/base_packages/poolparty.rb +36 -0
- data/lib/poolparty/base_packages/ruby.rb +43 -0
- data/lib/poolparty/core/array.rb +24 -0
- data/lib/{core → poolparty/core}/exception.rb +0 -0
- data/lib/poolparty/core/float.rb +13 -0
- data/lib/poolparty/core/hash.rb +29 -0
- data/lib/poolparty/core/kernel.rb +37 -0
- data/lib/{core → poolparty/core}/module.rb +18 -0
- data/lib/poolparty/core/my_open_struct.rb +18 -0
- data/lib/poolparty/core/object.rb +54 -0
- data/lib/poolparty/core/proc.rb +7 -0
- data/lib/poolparty/core/string.rb +72 -0
- data/lib/poolparty/core/symbol.rb +8 -0
- data/lib/{core → poolparty/core}/time.rb +15 -0
- data/lib/poolparty/exceptions/RemoteException.rb +12 -0
- data/lib/poolparty/exceptions/ResourceException.rb +7 -0
- data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
- data/lib/poolparty/exceptions/SpecException.rb +7 -0
- data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
- data/lib/poolparty/helpers/binary.rb +31 -0
- data/lib/poolparty/helpers/console.rb +30 -0
- data/lib/poolparty/helpers/display.rb +34 -0
- data/lib/poolparty/helpers/optioner.rb +64 -0
- data/lib/poolparty/helpers/provisioner_base.rb +250 -0
- data/lib/poolparty/helpers/provisioners/master.rb +136 -0
- data/lib/poolparty/helpers/provisioners/slave.rb +44 -0
- data/lib/poolparty/modules/cloud_resourcer.rb +89 -0
- data/lib/poolparty/modules/configurable.rb +34 -0
- data/lib/poolparty/modules/definable_resource.rb +59 -0
- data/lib/poolparty/modules/file_writer.rb +55 -0
- data/lib/poolparty/modules/method_missing_sugar.rb +53 -0
- data/lib/poolparty/modules/output.rb +13 -0
- data/lib/poolparty/modules/pretty_printer.rb +39 -0
- data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -22
- data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
- data/lib/poolparty/monitors/base_monitor.rb +16 -0
- data/lib/poolparty/net/remote.rb +35 -0
- data/lib/poolparty/net/remote_bases/ec2.rb +148 -0
- data/lib/poolparty/net/remote_instance.rb +69 -0
- data/lib/poolparty/net/remoter.rb +224 -0
- data/lib/poolparty/net/remoter_base.rb +117 -0
- data/lib/poolparty/plugins/gem_package.rb +17 -0
- data/lib/poolparty/plugins/git.rb +41 -0
- data/lib/poolparty/plugins/line.rb +76 -0
- data/lib/poolparty/plugins/svn.rb +48 -0
- data/lib/poolparty/pool/base.rb +75 -0
- data/lib/poolparty/pool/cloud.rb +164 -0
- data/lib/poolparty/pool/custom_resource.rb +61 -0
- data/lib/poolparty/pool/loggable.rb +29 -0
- data/lib/poolparty/pool/plugin.rb +41 -0
- data/lib/poolparty/pool/plugin_model.rb +48 -0
- data/lib/poolparty/pool/pool.rb +55 -0
- data/lib/poolparty/pool/resource.rb +248 -0
- data/lib/poolparty/pool/resources/class_package.rb +64 -0
- data/lib/poolparty/pool/resources/conditional.rb +41 -0
- data/lib/poolparty/pool/resources/cron.rb +14 -0
- data/lib/poolparty/pool/resources/directory.rb +23 -0
- data/lib/poolparty/pool/resources/exec.rb +26 -0
- data/lib/poolparty/pool/resources/file.rb +23 -0
- data/lib/poolparty/pool/resources/gem.rb +14 -0
- data/lib/poolparty/pool/resources/host.rb +14 -0
- data/lib/poolparty/pool/resources/package.rb +14 -0
- data/lib/poolparty/pool/resources/remote_file.rb +22 -0
- data/lib/poolparty/pool/resources/service.rb +21 -0
- data/lib/poolparty/pool/resources/sshkey.rb +19 -0
- data/lib/poolparty/pool/resources/variable.rb +27 -0
- data/lib/poolparty/pool/script.rb +44 -0
- data/lib/poolparty/templates/authkeys +2 -0
- data/{config/monit/nginx.monit.conf → lib/poolparty/templates/cib.xml} +0 -0
- data/lib/poolparty/templates/fileserver.conf +4 -0
- data/lib/poolparty/templates/gem +25 -0
- data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -2
- data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
- data/lib/poolparty/templates/namespaceauth.conf +19 -0
- data/lib/poolparty/templates/puppet.conf +17 -0
- data/lib/poolparty/version.rb +9 -0
- data/lib/poolpartycl.rb +3 -0
- data/poolparty.gemspec +56 -47
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/spec/poolparty/base_packages/haproxy_spec.rb +13 -0
- data/spec/poolparty/base_packages/heartbeat_spec.rb +30 -0
- data/spec/poolparty/bin/console_spec.rb +80 -0
- data/spec/poolparty/core/array_spec.rb +26 -0
- data/spec/poolparty/core/float.rb +13 -0
- data/spec/poolparty/core/hash_spec.rb +63 -0
- data/spec/poolparty/core/kernel_spec.rb +24 -0
- data/spec/poolparty/core/module_spec.rb +15 -0
- data/spec/poolparty/core/object_spec.rb +40 -0
- data/spec/poolparty/core/string_spec.rb +152 -0
- data/spec/poolparty/core/time_spec.rb +52 -0
- data/spec/poolparty/helpers/binary_spec.rb +26 -0
- data/spec/poolparty/helpers/display_spec.rb +13 -0
- data/spec/poolparty/helpers/optioner_spec.rb +39 -0
- data/spec/poolparty/helpers/provisioner_base_spec.rb +121 -0
- data/spec/poolparty/helpers/provisioners/master_spec.rb +54 -0
- data/spec/poolparty/helpers/provisioners/slave_spec.rb +28 -0
- data/spec/poolparty/modules/cloud_resourcer_spec.rb +135 -0
- data/spec/poolparty/modules/configurable_spec.rb +26 -0
- data/spec/poolparty/modules/definable_resource.rb +9 -0
- data/spec/poolparty/modules/file_writer_spec.rb +49 -0
- data/spec/poolparty/modules/s3_string_spec.rb +15 -0
- data/spec/poolparty/modules/tmp/willy/nilly.rb +1 -0
- data/spec/poolparty/net/remote_bases/ec2_spec.rb +92 -0
- data/spec/poolparty/net/remote_instance_spec.rb +70 -0
- data/spec/poolparty/net/remote_spec.rb +286 -0
- data/spec/poolparty/net/remoter_base_spec.rb +80 -0
- data/spec/poolparty/net/remoter_spec.rb +191 -0
- data/spec/poolparty/plugins/git_spec.rb +33 -0
- data/spec/poolparty/plugins/line_spec.rb +16 -0
- data/spec/poolparty/plugins/svn_spec.rb +16 -0
- data/spec/poolparty/pool/base_spec.rb +108 -0
- data/spec/poolparty/pool/cloud_spec.rb +299 -0
- data/spec/poolparty/pool/configurers/files/ruby_basic.rb +17 -0
- data/spec/poolparty/pool/configurers/files/ruby_plugins.rb +16 -0
- data/spec/poolparty/pool/configurers/ruby_spec.rb +58 -0
- data/spec/poolparty/pool/custom_resource_spec.rb +115 -0
- data/spec/poolparty/pool/example_spec.rb +112 -0
- data/spec/poolparty/pool/plugin_model_spec.rb +63 -0
- data/spec/poolparty/pool/plugin_spec.rb +85 -0
- data/spec/poolparty/pool/pool_spec.rb +83 -0
- data/spec/poolparty/pool/resource_spec.rb +224 -0
- data/spec/poolparty/pool/resources/class_package_spec.rb +84 -0
- data/spec/poolparty/pool/resources/conditional_spec.rb +38 -0
- data/spec/poolparty/pool/resources/cron_spec.rb +49 -0
- data/spec/poolparty/pool/resources/directory_spec.rb +40 -0
- data/spec/poolparty/pool/resources/exec_spec.rb +37 -0
- data/spec/poolparty/pool/resources/file_spec.rb +40 -0
- data/spec/poolparty/pool/resources/gem_spec.rb +16 -0
- data/spec/poolparty/pool/resources/host_spec.rb +28 -0
- data/spec/poolparty/pool/resources/package_spec.rb +44 -0
- data/spec/poolparty/pool/resources/remote_file_spec.rb +40 -0
- data/spec/poolparty/pool/resources/service_spec.rb +45 -0
- data/spec/poolparty/pool/resources/sshkey_spec.rb +48 -0
- data/spec/poolparty/pool/resources/variable_spec.rb +20 -0
- data/spec/poolparty/pool/script_spec.rb +51 -0
- data/spec/poolparty/pool/test_plugins/sshkey_test +2 -0
- data/{test/test_pool_party.rb → spec/poolparty/pool/test_plugins/virtual_host_template.erb} +0 -0
- data/spec/poolparty/pool/test_plugins/webserver.rb +46 -0
- data/spec/poolparty/poolparty_spec.rb +33 -0
- data/spec/poolparty/spec_helper.rb +120 -0
- data/tasks/cloud.rake +57 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/development.rake +78 -0
- data/tasks/ec2.rake +20 -0
- data/tasks/environment.rake +7 -0
- data/tasks/instance.rake +63 -0
- data/tasks/server.rake +42 -0
- data/tasks/spec.rake +17 -0
- data/tasks/website.rake +17 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_helper.rb +2 -0
- data/test/test_pool_spec_generator.rb +47 -0
- data/test/test_poolparty.rb +11 -0
- data/test_manifest.pp +538 -0
- data/website/index.html +107 -0
- data/website/index.txt +95 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/code.css +29 -0
- data/website/stylesheets/screen.css +147 -0
- data/website/template.html.erb +49 -0
- metadata +282 -101
- data/CHANGELOG +0 -4
- data/Manifest +0 -55
- data/bin/instance +0 -54
- data/config/config.yml +0 -23
- data/config/create_proxy_ami.sh +0 -582
- data/config/heartbeat_authkeys.conf +0 -2
- data/config/monit.conf +0 -8
- data/config/monit/haproxy.monit.conf +0 -7
- data/config/nginx.conf +0 -24
- data/lib/core/array.rb +0 -10
- data/lib/core/kernel.rb +0 -9
- data/lib/core/object.rb +0 -14
- data/lib/modules/callback.rb +0 -55
- data/lib/modules/ec2_wrapper.rb +0 -74
- data/lib/pool_party.rb +0 -69
- data/lib/pool_party/application.rb +0 -133
- data/lib/pool_party/init.rb +0 -4
- data/lib/pool_party/master.rb +0 -189
- data/lib/pool_party/monitors.rb +0 -13
- data/lib/pool_party/monitors/cpu.rb +0 -18
- data/lib/pool_party/monitors/memory.rb +0 -21
- data/lib/pool_party/monitors/web.rb +0 -18
- data/lib/pool_party/optioner.rb +0 -16
- data/lib/pool_party/os.rb +0 -11
- data/lib/pool_party/os/ubuntu.rb +0 -78
- data/lib/pool_party/remote_instance.rb +0 -180
- data/lib/pool_party/remoting.rb +0 -112
- data/lib/pool_party/scheduler.rb +0 -93
- data/lib/pool_party/tasks.rb +0 -220
- data/lib/s3/s3_object_store_folders.rb +0 -44
- data/spec/application_spec.rb +0 -32
- data/spec/callback_spec.rb +0 -65
- data/spec/helpers/ec2_mock.rb +0 -56
- data/spec/helpers/remote_instance_mock.rb +0 -11
- data/spec/kernel_spec.rb +0 -11
- data/spec/master_spec.rb +0 -147
- data/spec/monitor_spec.rb +0 -16
- data/spec/optioner_spec.rb +0 -22
- data/spec/poolparty_spec.rb +0 -8
- data/spec/remote_instance_spec.rb +0 -29
- data/spec/remoting_spec.rb +0 -75
- data/spec/spec_helper.rb +0 -38
- data/spec/string_spec.rb +0 -28
data/lib/pool_party/monitors.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
=begin rdoc
|
2
|
-
Basic monitor on the cpu stats
|
3
|
-
=end
|
4
|
-
module PoolParty
|
5
|
-
module Monitors
|
6
|
-
module Cpu
|
7
|
-
def self.monitor!
|
8
|
-
IO.popen("uptime") do |up|
|
9
|
-
ret = monitor_from_string(up)
|
10
|
-
end
|
11
|
-
ret
|
12
|
-
end
|
13
|
-
def self.monitor_from_string(str="")
|
14
|
-
str.split(/\s+/)[-3].to_f
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
=begin rdoc
|
2
|
-
Basic memory monitor on the instance
|
3
|
-
=end
|
4
|
-
module PoolParty
|
5
|
-
module Monitors
|
6
|
-
module Memory
|
7
|
-
def self.monitor!
|
8
|
-
IO.popen("free -m | grep -i mem") { |io|
|
9
|
-
ret = monitor_from_string(io)
|
10
|
-
}
|
11
|
-
ret
|
12
|
-
end
|
13
|
-
def self.monitor_from_string(str="")
|
14
|
-
total_memory = str.split[1].to_f
|
15
|
-
used_memory = str.split[2].to_f
|
16
|
-
|
17
|
-
used_memory / total_memory
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
=begin rdoc
|
2
|
-
Monitor the web stats for the request rate the server can handle at a time
|
3
|
-
=end
|
4
|
-
module PoolParty
|
5
|
-
module Monitors
|
6
|
-
module Web
|
7
|
-
def self.monitor!(port)
|
8
|
-
IO.popen("httperf --server localhost --port #{port} --num-conn 3 --timeout 5 | grep 'Request rate'") do |io|
|
9
|
-
@req = monitor_from_string(io.gets)
|
10
|
-
end
|
11
|
-
@req
|
12
|
-
end
|
13
|
-
def self.monitor_from_string(str="")
|
14
|
-
str[/[.]* ([\d]*\.[\d]*) [.]*/, 0].chomp.to_f
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/pool_party/optioner.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module PoolParty
|
2
|
-
class Optioner
|
3
|
-
# Parse the command line options for options without a switch
|
4
|
-
def self.parse(argv, safe=[])
|
5
|
-
args = []
|
6
|
-
argv.each_with_index do |arg,i|
|
7
|
-
unless arg.index("-")
|
8
|
-
args << arg
|
9
|
-
else
|
10
|
-
argv.delete_at(i+1) unless safe.include?(arg)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
args
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/pool_party/os.rb
DELETED
data/lib/pool_party/os/ubuntu.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
=begin rdoc
|
2
|
-
Ubuntu specific install tasks for PoolParty
|
3
|
-
=end
|
4
|
-
module PoolParty
|
5
|
-
module Os
|
6
|
-
module Ubuntu
|
7
|
-
def install_stack
|
8
|
-
install_haproxy
|
9
|
-
install_heartbeat
|
10
|
-
install_monit
|
11
|
-
install_s3fuse
|
12
|
-
end
|
13
|
-
def install_haproxy
|
14
|
-
cmd=<<-EOC
|
15
|
-
apt-get -y install haproxy
|
16
|
-
sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/haproxy
|
17
|
-
sed -i 's/SYSLOGD=\"\"/SYSLOGD=\"-r\"/g' /etc/default/syslogd
|
18
|
-
echo 'local0.* /var/log/haproxy.log' >> /etc/syslog.conf && killall -9 syslogd && syslogd
|
19
|
-
EOC
|
20
|
-
ssh cmd.runnable
|
21
|
-
end
|
22
|
-
def install_monit
|
23
|
-
cmd=<<-EOC
|
24
|
-
apt-get -y install monit
|
25
|
-
mkdir /etc/monit
|
26
|
-
sed -i 's/startup=0/startup=1/g' /etc/default/monit
|
27
|
-
/etc/init.d/monit start
|
28
|
-
EOC
|
29
|
-
ssh cmd.runnable
|
30
|
-
end
|
31
|
-
def install_nginx
|
32
|
-
cmd=<<-EOC
|
33
|
-
apt-get -y install nginx
|
34
|
-
EOC
|
35
|
-
ssh cmd.runnable
|
36
|
-
end
|
37
|
-
def install_heartbeat
|
38
|
-
cmd=<<-EOC
|
39
|
-
apt-get -y install heartbeat-2
|
40
|
-
EOC
|
41
|
-
ssh cmd.runnable
|
42
|
-
end
|
43
|
-
def install_s3fuse
|
44
|
-
cmd=<<-EOC
|
45
|
-
cd /usr/local/src && wget http://s3fs.googlecode.com/files/s3fs-r166-source.tar.gz
|
46
|
-
tar -zxf s3fs-r166-source.tar.gz
|
47
|
-
cd s3fs/ && make
|
48
|
-
mv s3fs /usr/bin
|
49
|
-
mkdir /data
|
50
|
-
EOC
|
51
|
-
ssh("apt-get -y install build-essential libcurl4-openssl-dev libxml2-dev libfuse-dev")
|
52
|
-
ssh(cmd.runnable)
|
53
|
-
end
|
54
|
-
# We want to slim this down...
|
55
|
-
def install_ruby_and_rubygems
|
56
|
-
cmd=<<-EOC
|
57
|
-
echo 'Installing ruby...'
|
58
|
-
ln -sf /usr/bin/ruby1.8 /usr/local/bin/ruby
|
59
|
-
ln -sf /usr/bin/ri1.8 /usr/local/bin/ri
|
60
|
-
ln -sf /usr/bin/rdoc1.8 /usr/local/bin/rdoc
|
61
|
-
ln -sf /usr/bin/irb1.8 /usr/local/bin/irb
|
62
|
-
echo '-- Installing Rubygems'
|
63
|
-
cd /usr/local/src
|
64
|
-
wget http://rubyforge.org/frs/download.php/35283/rubygems-1.1.1.tgz
|
65
|
-
tar -xzf rubygems-1.1.1.tgz
|
66
|
-
cd rubygems-1.1.1
|
67
|
-
ruby setup.rb --no-rdoc --no-ri
|
68
|
-
ln -sf /usr/bin/gem1.8 /usr/bin/gem
|
69
|
-
gem1.8 update --system
|
70
|
-
gem1.8 install aws-s3 amazon-ec2 aska rake poolparty --no-rdoc --no-ri --no-test
|
71
|
-
EOC
|
72
|
-
ssh("apt-get -y install build-essential ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8")
|
73
|
-
ssh(cmd.runnable)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
module PoolParty
|
2
|
-
class RemoteInstance
|
3
|
-
include PoolParty # WTF -> why isn't message included
|
4
|
-
include Callbacks
|
5
|
-
|
6
|
-
attr_reader :ip, :instance_id, :name, :number, :status, :launching_time, :stack_installed
|
7
|
-
attr_accessor :name
|
8
|
-
|
9
|
-
def initialize(obj)
|
10
|
-
@ip = obj[:ip]
|
11
|
-
@instance_id = obj[:instance_id]
|
12
|
-
@name = obj[:name] || "node"
|
13
|
-
@number = obj[:number] || 0 # Defaults to the master
|
14
|
-
@status = obj[:status] || "running"
|
15
|
-
@launching_time = obj[:launching_time] || Time.now
|
16
|
-
end
|
17
|
-
|
18
|
-
# Host entry for this instance
|
19
|
-
def hosts_entry
|
20
|
-
"#{@ip}\t#{name}"
|
21
|
-
end
|
22
|
-
# Internal host entry for this instance
|
23
|
-
def local_hosts_entry
|
24
|
-
"127.0.0.1 #{name}\n127.0.0.1 localhost.localdomain localhost ubuntu"
|
25
|
-
end
|
26
|
-
# Node entry for heartbeat
|
27
|
-
def node_entry
|
28
|
-
"node #{name}"
|
29
|
-
end
|
30
|
-
# Internal naming scheme
|
31
|
-
def name
|
32
|
-
"#{@name}#{@number}"
|
33
|
-
end
|
34
|
-
# Entry for the heartbeat config file
|
35
|
-
def heartbeat_entry
|
36
|
-
"#{name} #{ip} #{Application.managed_services}"
|
37
|
-
end
|
38
|
-
# Entry for haproxy
|
39
|
-
def haproxy_entry
|
40
|
-
"server #{name} #{@ip}:#{Application.client_port} weight 1 check"
|
41
|
-
end
|
42
|
-
def haproxy_resources_entry
|
43
|
-
"#{name}\t#{@ip}"
|
44
|
-
end
|
45
|
-
# Is this the master?
|
46
|
-
def master?
|
47
|
-
@number == 0
|
48
|
-
end
|
49
|
-
# Let's define some stuff for monit
|
50
|
-
%w(stop start restart).each do |cmd|
|
51
|
-
define_method "#{cmd}_with_monit" do
|
52
|
-
ssh("monit #{cmd} all")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
# Gets called everytime the cloud reloads itself
|
56
|
-
# This is how the cloud reconfigures itself
|
57
|
-
def configure
|
58
|
-
configure_master if master?
|
59
|
-
configure_linux
|
60
|
-
configure_hosts
|
61
|
-
configure_haproxy
|
62
|
-
configure_heartbeat if Master.requires_heartbeat?
|
63
|
-
configure_s3fuse
|
64
|
-
configure_monit
|
65
|
-
end
|
66
|
-
# Setup the master tasks
|
67
|
-
def configure_master
|
68
|
-
message "configuring master (#{name})"
|
69
|
-
install_ruby_and_rubygems # Install ruby and the gems required to run the master
|
70
|
-
scp(Application.config_file, "~/.config")
|
71
|
-
ssh("pool maintain -C ~/.config") # Let's set it to maintain, ey?
|
72
|
-
end
|
73
|
-
# Change the hostname for the instance
|
74
|
-
def configure_linux
|
75
|
-
ssh("'hostname -v #{name}'") rescue message "error in setting hostname"
|
76
|
-
end
|
77
|
-
# Configure s3fs if the bucket is specified in the config.yml
|
78
|
-
def configure_s3fuse
|
79
|
-
message("Configuring s3fuse")
|
80
|
-
|
81
|
-
unless Application.shared_bucket.empty?
|
82
|
-
install_s3fuse unless ssh("s3fs -v") =~ /missing\ bucket/
|
83
|
-
ssh("/usr/bin/s3fs #{Application.shared_bucket} -ouse_cache=/tmp -o accessKeyId=#{Application.access_key} -o secretAccessKey=#{Application.secret_access_key} -o nonempty /data")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
# Configure heartbeat only if there is enough servers
|
87
|
-
def configure_heartbeat
|
88
|
-
message "Configuring heartbeat"
|
89
|
-
install_heartbeat unless has?("heartbeat")
|
90
|
-
|
91
|
-
file = write_to_temp_file(open(Application.heartbeat_authkeys_config_file).read.strip)
|
92
|
-
scp(file.path, "/etc/ha.d/authkeys")
|
93
|
-
|
94
|
-
file = Master.build_heartbeat_config_file_for(self)
|
95
|
-
scp(file.path, "/etc/ha.d/ha.cf")
|
96
|
-
|
97
|
-
file = Master.build_heartbeat_resources_file_for(self)
|
98
|
-
scp(file.path, "/etc/ha.d/haresources")
|
99
|
-
end
|
100
|
-
# Some configures for monit
|
101
|
-
def configure_monit
|
102
|
-
message "Configuring monit"
|
103
|
-
install_monit unless has?("monit -V")
|
104
|
-
|
105
|
-
scp(Application.monit_config_file, "/etc/monit/monitrc")
|
106
|
-
ssh("mkdir /etc/monit.d")
|
107
|
-
Dir["#{File.dirname(Application.monit_config_file)}/monit/*"].each do |f|
|
108
|
-
scp(f, "/etc/monit.d/#{File.basename(f)}")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
# Configure haproxy
|
112
|
-
def configure_haproxy
|
113
|
-
message "Configuring haproxy"
|
114
|
-
install_haproxy unless has?("haproxy")
|
115
|
-
|
116
|
-
file = Master.new.build_haproxy_file
|
117
|
-
scp(file.path, "/etc/haproxy.cfg")
|
118
|
-
end
|
119
|
-
# Configure the hosts for the linux file
|
120
|
-
def configure_hosts
|
121
|
-
message "Configuring hosts"
|
122
|
-
file = Master.build_hosts_file_for(self)
|
123
|
-
scp(file.path, "/etc/hosts") rescue message "Error in uploading new /etc/hosts file"
|
124
|
-
end
|
125
|
-
# Restart all services with monit
|
126
|
-
# Send a generic version command to test if the stdout contains
|
127
|
-
# any information to test if the software is on the instance
|
128
|
-
def has?(str)
|
129
|
-
!ssh("#{str} -v").empty?
|
130
|
-
end
|
131
|
-
# MONITORS
|
132
|
-
# Monitor the number of web requests that can be accepted at a time
|
133
|
-
def web
|
134
|
-
Monitors::Web.monitor_from_string ssh("httperf --server localhost --port #{Application.client_port} --num-conn 3 --timeout 5 | grep 'Request rate'") rescue 0.0
|
135
|
-
end
|
136
|
-
# Monitor the cpu status of the instance
|
137
|
-
def cpu
|
138
|
-
Monitors::Cpu.monitor_from_string ssh("uptime") rescue 0.0
|
139
|
-
end
|
140
|
-
# Monitor the memory
|
141
|
-
def memory
|
142
|
-
Monitors::Memory.monitor_from_string ssh("free -m | grep -i mem") rescue 0.0
|
143
|
-
end
|
144
|
-
# Scp src to dest on the instance
|
145
|
-
def scp(src="", dest="")
|
146
|
-
`scp -i #{Application.keypair_path} #{src} #{Application.username}@#{@ip}:#{dest}`
|
147
|
-
end
|
148
|
-
# Ssh into the instance or run a command, if the cmd is set
|
149
|
-
def ssh(cmd="")
|
150
|
-
ssh = "ssh -i #{Application.keypair_path} #{Application.username}@#{@ip}"
|
151
|
-
|
152
|
-
cmd.empty? ? system("#{ssh}") : %x[#{ssh} '#{cmd.runnable}']
|
153
|
-
end
|
154
|
-
|
155
|
-
# Description in the rake task
|
156
|
-
def description
|
157
|
-
case @status
|
158
|
-
when "running"
|
159
|
-
"#{@number}: INSTANCE: #{name} - #{@ip} - #{@instance_id} - #{@launching_time}"
|
160
|
-
when "shutting-down"
|
161
|
-
"(terminating) INSTANCE: #{name} - #{@ip} - #{@instance_id} - #{@launching_time}"
|
162
|
-
when "pending"
|
163
|
-
"(booting) INSTANCE: #{name} - #{@ip} - #{@instance_id} - #{@launching_time}"
|
164
|
-
end
|
165
|
-
end
|
166
|
-
def stack_installed?
|
167
|
-
@stack_installed == true
|
168
|
-
end
|
169
|
-
def mark_installed
|
170
|
-
@stack_installed = true
|
171
|
-
end
|
172
|
-
# Include the os specific tasks as specified in the application options (config.yml)
|
173
|
-
instance_eval "include PoolParty::Os::#{Application.os.capitalize}"
|
174
|
-
|
175
|
-
# CALLBACKS
|
176
|
-
after :install_stack, :configure # After we install the stack, let's make sure we configure it too
|
177
|
-
before :configure, :mark_installed # We want to make sure
|
178
|
-
after :configure, :restart_with_monit # Anytime we configure the server, we want the server to restart it's services
|
179
|
-
end
|
180
|
-
end
|
data/lib/pool_party/remoting.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
module PoolParty
|
2
|
-
extend self
|
3
|
-
|
4
|
-
class Remoting
|
5
|
-
include PoolParty
|
6
|
-
include Ec2Wrapper
|
7
|
-
include Scheduler
|
8
|
-
|
9
|
-
# == GENERAL METHODS
|
10
|
-
# == LISTING
|
11
|
-
# List all the running instances associated with this account
|
12
|
-
def list_of_running_instances
|
13
|
-
list_of_nonterminated_instances.select {|a| a[:status] =~ /running/}
|
14
|
-
end
|
15
|
-
# Get a list of the pending instances
|
16
|
-
def list_of_pending_instances
|
17
|
-
list_of_nonterminated_instances.select {|a| a[:status] =~ /pending/}
|
18
|
-
end
|
19
|
-
# list of shutting down instances
|
20
|
-
def list_of_terminating_instances
|
21
|
-
list_of_nonterminated_instances.select {|a| a[:status] =~ /shutting/}
|
22
|
-
end
|
23
|
-
# list all the nonterminated instances
|
24
|
-
def list_of_nonterminated_instances
|
25
|
-
list_of_instances.reject {|a| a[:status] =~ /terminated/}
|
26
|
-
end
|
27
|
-
# List the instances, regardless of their states
|
28
|
-
def list_of_instances
|
29
|
-
get_instances_description
|
30
|
-
end
|
31
|
-
# Get number of pending instances
|
32
|
-
def number_of_pending_instances
|
33
|
-
list_of_pending_instances.size
|
34
|
-
end
|
35
|
-
# get the number of running instances
|
36
|
-
def number_of_running_instances
|
37
|
-
list_of_running_instances.size
|
38
|
-
end
|
39
|
-
# get the number of pending and running instances
|
40
|
-
def number_of_pending_and_running_instances
|
41
|
-
number_of_running_instances + number_of_pending_instances
|
42
|
-
end
|
43
|
-
# == LAUNCHING
|
44
|
-
# Request to launch a new instance
|
45
|
-
def request_launch_new_instance
|
46
|
-
if can_start_a_new_instance?
|
47
|
-
request_launch_one_instance_at_a_time
|
48
|
-
return true
|
49
|
-
else
|
50
|
-
return false
|
51
|
-
end
|
52
|
-
end
|
53
|
-
# Can we start a new instance?
|
54
|
-
def can_start_a_new_instance?
|
55
|
-
maximum_number_of_instances_are_not_running?
|
56
|
-
end
|
57
|
-
# Are the maximum number of instances running?
|
58
|
-
def maximum_number_of_instances_are_not_running?
|
59
|
-
list_of_running_instances.size < Application.maximum_instances
|
60
|
-
end
|
61
|
-
# Request to launch a number of instances
|
62
|
-
def request_launch_new_instances(num=1)
|
63
|
-
out = []
|
64
|
-
num.times {out << request_launch_one_instance_at_a_time}
|
65
|
-
out
|
66
|
-
end
|
67
|
-
# Launch one instance at a time
|
68
|
-
def request_launch_one_instance_at_a_time
|
69
|
-
reset!
|
70
|
-
while !number_of_pending_instances.zero?
|
71
|
-
wait "5.seconds"
|
72
|
-
reset!
|
73
|
-
end
|
74
|
-
return launch_new_instance!
|
75
|
-
end
|
76
|
-
# == SHUTDOWN
|
77
|
-
# Terminate all running instances
|
78
|
-
def request_termination_of_running_instances
|
79
|
-
list_of_running_instances.each {|a| terminate_instance!(a[:instance_id])}
|
80
|
-
end
|
81
|
-
# Request termination of all instances regardless of their state (includes pending instances)
|
82
|
-
def request_termination_of_all_instances
|
83
|
-
get_instances_description.each {|a| terminate_instance!(a[:instance_id])}
|
84
|
-
end
|
85
|
-
# Terminate instance by id
|
86
|
-
def request_termination_of_instance(id)
|
87
|
-
if can_shutdown_an_instance?
|
88
|
-
terminate_instance! id
|
89
|
-
return true
|
90
|
-
else
|
91
|
-
return false
|
92
|
-
end
|
93
|
-
end
|
94
|
-
# Can we shutdown an instance?
|
95
|
-
def can_shutdown_an_instance?
|
96
|
-
minimum_number_of_instances_are_running?
|
97
|
-
end
|
98
|
-
# Are the minimum number of instances running?
|
99
|
-
def minimum_number_of_instances_are_running?
|
100
|
-
list_of_running_instances.size > Application.minimum_instances
|
101
|
-
end
|
102
|
-
# Get the cached running_instances
|
103
|
-
def running_instances
|
104
|
-
@running_instances ||= update_instance_values
|
105
|
-
end
|
106
|
-
# Update the instance values
|
107
|
-
def update_instance_values
|
108
|
-
@running_instances = list_of_running_instances.collect {|a| RemoteInstance.new(a) }.sort
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|