auser-poolparty 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/History.txt +22 -0
  2. data/License.txt +20 -0
  3. data/README.txt +52 -0
  4. data/Rakefile +4 -109
  5. data/bin/cloud +31 -0
  6. data/bin/cloud-add-keypair +23 -0
  7. data/bin/cloud-configure +35 -0
  8. data/bin/cloud-contract +27 -0
  9. data/bin/cloud-expand +27 -0
  10. data/bin/cloud-list +32 -0
  11. data/bin/cloud-maintain +36 -0
  12. data/bin/cloud-provision +30 -0
  13. data/bin/cloud-reconfigure +24 -0
  14. data/bin/cloud-ssh +18 -0
  15. data/bin/cloud-start +29 -0
  16. data/bin/pool +23 -75
  17. data/bin/pool-console +12 -0
  18. data/bin/pool-describe +9 -0
  19. data/bin/pool-list +28 -0
  20. data/bin/pool-provision +34 -0
  21. data/bin/pool-spec +17 -0
  22. data/bin/pool-start +32 -0
  23. data/examples/basic.rb +20 -0
  24. data/examples/plugin_without_plugin_directory.rb +13 -0
  25. data/examples/poolparty.rb +12 -0
  26. data/examples/with_apache_plugin.rb +22 -0
  27. data/generators/poolspec/USAGE +5 -0
  28. data/generators/poolspec/poolspec_generator.rb +65 -0
  29. data/generators/poolspec/templates/pool_spec_template.erb +9 -0
  30. data/lib/erlang/eb_server.erl +27 -0
  31. data/lib/poolparty.rb +40 -116
  32. data/lib/poolparty/base_packages/haproxy.rb +41 -0
  33. data/lib/poolparty/base_packages/heartbeat.rb +43 -0
  34. data/lib/poolparty/base_packages/poolparty.rb +18 -0
  35. data/lib/poolparty/base_packages/ruby.rb +27 -0
  36. data/lib/poolparty/core/array.rb +24 -0
  37. data/lib/{core → poolparty/core}/exception.rb +0 -0
  38. data/lib/{core → poolparty/core}/float.rb +0 -0
  39. data/lib/poolparty/core/hash.rb +29 -0
  40. data/lib/poolparty/core/kernel.rb +34 -0
  41. data/lib/{core → poolparty/core}/module.rb +18 -0
  42. data/lib/poolparty/core/my_open_struct.rb +18 -0
  43. data/lib/poolparty/core/object.rb +54 -0
  44. data/lib/poolparty/core/proc.rb +2 -0
  45. data/lib/poolparty/core/string.rb +72 -0
  46. data/lib/poolparty/core/symbol.rb +8 -0
  47. data/lib/{core → poolparty/core}/time.rb +15 -0
  48. data/lib/poolparty/exceptions/RemoteException.rb +12 -0
  49. data/lib/poolparty/exceptions/ResourceException.rb +7 -0
  50. data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
  51. data/lib/poolparty/exceptions/SpecException.rb +7 -0
  52. data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
  53. data/lib/poolparty/helpers/binary.rb +30 -0
  54. data/lib/poolparty/helpers/console.rb +30 -0
  55. data/lib/poolparty/helpers/display.rb +25 -0
  56. data/lib/poolparty/helpers/optioner.rb +61 -0
  57. data/lib/poolparty/helpers/provisioner_base.rb +226 -0
  58. data/lib/poolparty/helpers/provisioners/master.rb +120 -0
  59. data/lib/poolparty/helpers/provisioners/slave.rb +52 -0
  60. data/lib/poolparty/modules/cloud_resourcer.rb +72 -0
  61. data/lib/poolparty/modules/configurable.rb +34 -0
  62. data/lib/poolparty/modules/definable_resource.rb +59 -0
  63. data/lib/poolparty/modules/file_writer.rb +55 -0
  64. data/lib/poolparty/modules/method_missing_sugar.rb +17 -0
  65. data/lib/poolparty/modules/output.rb +13 -0
  66. data/lib/poolparty/modules/pretty_printer.rb +38 -0
  67. data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -29
  68. data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
  69. data/lib/poolparty/monitors/base_monitor.rb +16 -0
  70. data/lib/poolparty/net/remote.rb +35 -0
  71. data/lib/poolparty/net/remote_bases/ec2.rb +145 -0
  72. data/lib/poolparty/net/remote_instance.rb +68 -0
  73. data/lib/poolparty/net/remoter.rb +209 -0
  74. data/lib/poolparty/net/remoter_base.rb +117 -0
  75. data/lib/poolparty/plugins/gem_package.rb +39 -0
  76. data/lib/poolparty/plugins/line.rb +76 -0
  77. data/lib/poolparty/plugins/svn.rb +48 -0
  78. data/lib/poolparty/pool/base.rb +74 -0
  79. data/lib/poolparty/pool/cloud.rb +132 -0
  80. data/lib/poolparty/pool/custom_resource.rb +61 -0
  81. data/lib/poolparty/pool/loggable.rb +29 -0
  82. data/lib/poolparty/pool/plugin.rb +42 -0
  83. data/lib/poolparty/pool/plugin_model.rb +48 -0
  84. data/lib/poolparty/pool/pool.rb +55 -0
  85. data/lib/poolparty/pool/resource.rb +235 -0
  86. data/lib/poolparty/pool/resources/class_package.rb +60 -0
  87. data/lib/poolparty/pool/resources/cron.rb +14 -0
  88. data/lib/poolparty/pool/resources/directory.rb +23 -0
  89. data/lib/poolparty/pool/resources/exec.rb +26 -0
  90. data/lib/poolparty/pool/resources/file.rb +23 -0
  91. data/lib/poolparty/pool/resources/gem.rb +14 -0
  92. data/lib/poolparty/pool/resources/host.rb +14 -0
  93. data/lib/poolparty/pool/resources/package.rb +14 -0
  94. data/lib/poolparty/pool/resources/remote_file.rb +20 -0
  95. data/lib/poolparty/pool/resources/service.rb +21 -0
  96. data/lib/poolparty/pool/resources/sshkey.rb +19 -0
  97. data/lib/poolparty/pool/resources/variable.rb +27 -0
  98. data/lib/poolparty/pool/script.rb +21 -0
  99. data/{config/heartbeat_authkeys.conf → lib/poolparty/templates/authkeys} +0 -0
  100. data/lib/poolparty/templates/cib.xml +1 -0
  101. data/lib/poolparty/templates/fileserver.conf +4 -0
  102. data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -1
  103. data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
  104. data/lib/poolparty/templates/namespaceauth.conf +19 -0
  105. data/lib/poolparty/templates/puppet.conf +13 -0
  106. data/lib/poolparty/version.rb +9 -0
  107. data/lib/poolpartycl.rb +3 -0
  108. data/script/destroy +14 -0
  109. data/script/generate +14 -0
  110. data/script/txt2html +82 -0
  111. data/{lib/poolparty/tasks → tasks}/cloud.rake +1 -1
  112. data/tasks/deployment.rake +34 -0
  113. data/tasks/development.rake +78 -0
  114. data/{lib/poolparty/tasks → tasks}/ec2.rake +1 -1
  115. data/tasks/environment.rake +7 -0
  116. data/{lib/poolparty/tasks → tasks}/instance.rake +0 -0
  117. data/{lib/poolparty/tasks → tasks}/server.rake +0 -0
  118. data/tasks/spec.rake +17 -0
  119. data/tasks/website.rake +17 -0
  120. metadata +154 -249
  121. data/CHANGELOG +0 -23
  122. data/LICENSE +0 -22
  123. data/README +0 -139
  124. data/assets/clouds.png +0 -0
  125. data/bin/instance +0 -68
  126. data/bin/poolnotify +0 -34
  127. data/config/cloud_master_takeover +0 -17
  128. data/config/create_proxy_ami.sh +0 -582
  129. data/config/installers/ubuntu_install.sh +0 -77
  130. data/config/monit.conf +0 -9
  131. data/config/monit/haproxy.monit.conf +0 -8
  132. data/config/monit/nginx.monit.conf +0 -0
  133. data/config/nginx.conf +0 -24
  134. data/config/reconfigure_instances_script.sh +0 -37
  135. data/config/sample-config.yml +0 -23
  136. data/config/scp_instances_script.sh +0 -12
  137. data/lib/core/array.rb +0 -16
  138. data/lib/core/hash.rb +0 -11
  139. data/lib/core/kernel.rb +0 -12
  140. data/lib/core/object.rb +0 -21
  141. data/lib/core/proc.rb +0 -15
  142. data/lib/helpers/plugin_spec_helper.rb +0 -58
  143. data/lib/modules/callback.rb +0 -133
  144. data/lib/modules/ec2_wrapper.rb +0 -108
  145. data/lib/modules/file_writer.rb +0 -38
  146. data/lib/modules/sprinkle_overrides.rb +0 -27
  147. data/lib/modules/vlad_override.rb +0 -83
  148. data/lib/poolparty/application.rb +0 -199
  149. data/lib/poolparty/init.rb +0 -6
  150. data/lib/poolparty/master.rb +0 -492
  151. data/lib/poolparty/monitors.rb +0 -11
  152. data/lib/poolparty/monitors/cpu.rb +0 -23
  153. data/lib/poolparty/monitors/memory.rb +0 -33
  154. data/lib/poolparty/monitors/web.rb +0 -29
  155. data/lib/poolparty/optioner.rb +0 -20
  156. data/lib/poolparty/plugin.rb +0 -78
  157. data/lib/poolparty/provider.rb +0 -104
  158. data/lib/poolparty/provider/essential.rb +0 -6
  159. data/lib/poolparty/provider/git.rb +0 -8
  160. data/lib/poolparty/provider/haproxy.rb +0 -9
  161. data/lib/poolparty/provider/heartbeat.rb +0 -6
  162. data/lib/poolparty/provider/rsync.rb +0 -8
  163. data/lib/poolparty/provider/ruby.rb +0 -65
  164. data/lib/poolparty/provider/s3fuse.rb +0 -22
  165. data/lib/poolparty/remote_instance.rb +0 -250
  166. data/lib/poolparty/remoter.rb +0 -171
  167. data/lib/poolparty/remoting.rb +0 -137
  168. data/lib/poolparty/scheduler.rb +0 -93
  169. data/lib/poolparty/tasks.rb +0 -47
  170. data/lib/poolparty/tasks/development.rake +0 -78
  171. data/lib/poolparty/tasks/plugins.rake +0 -30
  172. data/lib/poolparty/thread_pool.rb +0 -94
  173. data/lib/s3/s3_object_store_folders.rb +0 -44
  174. data/poolparty.gemspec +0 -71
  175. data/spec/files/describe_response +0 -37
  176. data/spec/files/multi_describe_response +0 -69
  177. data/spec/files/remote_desc_response +0 -37
  178. data/spec/helpers/ec2_mock.rb +0 -57
  179. data/spec/lib/core/core_spec.rb +0 -26
  180. data/spec/lib/core/kernel_spec.rb +0 -24
  181. data/spec/lib/core/string_spec.rb +0 -28
  182. data/spec/lib/modules/callback_spec.rb +0 -213
  183. data/spec/lib/modules/file_writer_spec.rb +0 -74
  184. data/spec/lib/poolparty/application_spec.rb +0 -135
  185. data/spec/lib/poolparty/ec2_wrapper_spec.rb +0 -110
  186. data/spec/lib/poolparty/master_spec.rb +0 -479
  187. data/spec/lib/poolparty/optioner_spec.rb +0 -34
  188. data/spec/lib/poolparty/plugin_spec.rb +0 -115
  189. data/spec/lib/poolparty/poolparty_spec.rb +0 -60
  190. data/spec/lib/poolparty/provider_spec.rb +0 -74
  191. data/spec/lib/poolparty/remote_instance_spec.rb +0 -178
  192. data/spec/lib/poolparty/remoter_spec.rb +0 -72
  193. data/spec/lib/poolparty/remoting_spec.rb +0 -148
  194. data/spec/lib/poolparty/scheduler_spec.rb +0 -70
  195. data/spec/monitors/cpu_monitor_spec.rb +0 -39
  196. data/spec/monitors/memory_spec.rb +0 -51
  197. data/spec/monitors/misc_monitor_spec.rb +0 -51
  198. data/spec/monitors/web_spec.rb +0 -40
  199. data/spec/spec_helper.rb +0 -53
@@ -1,108 +0,0 @@
1
- module PoolParty
2
- extend self
3
-
4
- module Ec2Wrapper
5
-
6
- module ClassMethods
7
- end
8
-
9
- module InstanceMethods
10
- # Run a new instance, with the user_data and the ami described in the config
11
- def launch_new_instance!
12
- instance = ec2.run_instances(
13
- :image_id => Application.ami,
14
- :user_data => "#{Application.launching_user_data}",
15
- :minCount => 1,
16
- :maxCount => 1,
17
- :key_name => "#{Application.keypair}",
18
- :availability_zone => nil,
19
- :size => "#{Application.size}")
20
- begin
21
- item = instance#.instancesSet.item
22
- EC2ResponseObject.get_hash_from_response(item)
23
- rescue Exception => e
24
- end
25
- end
26
- # Shutdown the instance by instance_id
27
- def terminate_instance!(instance_id)
28
- ec2.terminate_instances(:instance_id => instance_id)
29
- end
30
- def associate_address_with(ip, instance_id)
31
- ec2.associate_address(:instance_id => instance_id, :public_ip => ip)
32
- end
33
- # Instance description
34
- def describe_instance(id)
35
- EC2ResponseObject.get_hash_from_response(ec2.describe_instances(:instance_id => id))
36
- end
37
- # Get instance by id
38
- def get_instance_by_id(id)
39
- get_instances_description.select {|a| a.instance_id == id}[0] rescue nil
40
- end
41
- # Get the s3 description for the response in a hash format
42
- def get_instances_description
43
- @cached_descriptions ||= EC2ResponseObject.get_descriptions(ec2.describe_instances)
44
- end
45
- # EC2 connections
46
- def ec2
47
- @ec2 ||= EC2::Base.new(:access_key_id => Application.access_key, :secret_access_key => Application.secret_access_key)
48
- end
49
- def reset!
50
- @cached_descriptions = nil
51
- end
52
- end
53
-
54
- def self.included(receiver)
55
- receiver.extend ClassMethods
56
- receiver.send :include, InstanceMethods
57
- end
58
- end
59
- # Provides a simple class to wrap around the amazon responses
60
- class EC2ResponseObject
61
- def self.get_descriptions(resp)
62
- rs = get_response_from(resp)
63
-
64
- # puts rs.methods.sort - rs.ancestors.methods
65
- out = begin
66
- if rs.respond_to?(:instancesSet)
67
- [EC2ResponseObject.get_hash_from_response(rs.instancesSet.item)]
68
- else
69
- rs.collect {|r|
70
- if r.instancesSet.item.class == Array
71
- r.instancesSet.item.map {|t| EC2ResponseObject.get_hash_from_response(t)}
72
- else
73
- [EC2ResponseObject.get_hash_from_response(r.instancesSet.item)]
74
- end
75
- }.flatten.reject {|a| a.nil? }
76
- end
77
- rescue Exception => e
78
- # Really weird bug with amazon's ec2 gem
79
- rs.collect {|r| EC2ResponseObject.get_hash_from_response(r)}.reject {|a| a.nil? } rescue []
80
- end
81
-
82
- out
83
- end
84
- def self.get_response_from(resp)
85
- begin
86
- rs = resp.reservationSet.item unless resp.reservationSet.nil?
87
- rs ||= resp.DescribeInstancesResponse.reservationSet.item
88
- rs ||= rs.respond_to?(:instancesSet) ? rs.instancesSet : rs
89
- rs.reject! {|a| a.nil? || a.empty? }
90
- rescue Exception => e
91
- end
92
- rs
93
- end
94
- def self.get_hash_from_response(resp)
95
- begin
96
- {
97
- :instance_id => resp.instanceId,
98
- :ip => resp.dnsName,
99
- :status => resp.instanceState.name,
100
- :launching_time => resp.launchTime,
101
- :keypair => resp.keyName
102
- }
103
- rescue Exception => e
104
- nil
105
- end
106
- end
107
- end
108
- end
@@ -1,38 +0,0 @@
1
- module PoolParty
2
- module FileWriter
3
- def write_to_file_for(f="haproxy", node=nil, str="", &block)
4
- make_base_directory
5
- File.open("#{base_tmp_dir}/#{node ? "#{node.name}-" : ""}#{f}", "w+") do |file|
6
- file << str
7
- file << block.call if block_given?
8
- end
9
- end
10
- # Write a temp file with the content str
11
- def write_to_temp_file(str="")
12
- tempfile = Tempfile.new("#{base_tmp_dir}/poolparty-#{rand(1000)}-#{rand(1000)}")
13
- tempfile.print(str)
14
- tempfile.flush
15
- tempfile
16
- end
17
- def with_temp_file(str="", &block)
18
- Tempfile.open "#{base_tmp_dir}/poolparty-#{rand(10000)}" do |fp|
19
- fp.puts str
20
- fp.flush
21
- block.call(fp)
22
- end
23
- end
24
-
25
- def base_tmp_dir
26
- File.join(user_dir, "tmp")
27
- end
28
- def remote_base_tmp_dir
29
- "~/tmp"
30
- end
31
- def make_base_directory
32
- `mkdir -p #{base_tmp_dir}` unless File.directory?(base_tmp_dir)
33
- end
34
- def clear_base_directory
35
- `rm -rf #{base_tmp_dir}/*` if File.directory?(base_tmp_dir)
36
- end
37
- end
38
- end
@@ -1,27 +0,0 @@
1
- Sprinkle::Installers::Source.extend Module.new do
2
- def custom_dir(dir)
3
- @custom_dir = dir
4
- end
5
-
6
- def base_dir
7
- if @custom_dir
8
- return @custom_dir
9
- elsif @source.split('/').last =~ /(.*)\.(tar\.gz|tgz|tar\.bz2|tb2)/
10
- return $1
11
- end
12
- raise "Unknown base path for source archive: #{@source}, please update code knowledge"
13
- end
14
- end
15
- Sprinkle::Installers::Gem.extend Module.new do
16
- def platform(platform=nil)
17
- @platform ||= platform
18
- end
19
- protected
20
- def install_sequence
21
- cmd = "gem install -y #{gem}"
22
- cmd << " --version '#{version}'" if version
23
- cmd << " --source #{source}" if source
24
- cmd << " --platform #{platform}" if platform
25
- cmd
26
- end
27
- end
@@ -1,83 +0,0 @@
1
- # require "vlad"
2
- # class Rake::RemoteTask < Rake::Task
3
- # def run command
4
- # cmd = [ssh_cmd, ssh_flags, target_host].compact
5
- # result = []
6
- #
7
- # commander = cmd.join(" ") << " \"#{command}\""
8
- # warn commander if $TRACE
9
- #
10
- # pid, inn, out, err = popen4(commander)
11
- #
12
- # inn.sync = true
13
- # streams = [out, err]
14
- # out_stream = {
15
- # out => $stdout,
16
- # err => $stderr,
17
- # }
18
- #
19
- # # Handle process termination ourselves
20
- # status = nil
21
- # Thread.start do
22
- # status = Process.waitpid2(pid).last
23
- # end
24
- #
25
- # until streams.empty? do
26
- # # don't busy loop
27
- # selected, = select streams, nil, nil, 0.1
28
- #
29
- # next if selected.nil? or selected.empty?
30
- #
31
- # selected.each do |stream|
32
- # if stream.eof? then
33
- # streams.delete stream if status # we've quit, so no more writing
34
- # next
35
- # end
36
- #
37
- # data = stream.readpartial(1024)
38
- # out_stream[stream].write data
39
- #
40
- # if stream == err and data =~ /^Password:/ then
41
- # inn.puts sudo_password
42
- # data << "\n"
43
- # $stderr.write "\n"
44
- # end
45
- #
46
- # result << data
47
- # end
48
- # end
49
- #
50
- # PoolParty.message "execution failed with status #{status.exitstatus}: #{cmd.join ' '}" unless status.success?
51
- #
52
- # result.join
53
- # end
54
- #
55
- # def rsync local, remote
56
- # cmd = [rsync_cmd, rsync_flags, local, "#{@target_host}:#{remote}"].flatten.compact
57
- #
58
- # success = system(*cmd.join(" "))
59
- #
60
- # unless success then
61
- # raise Vlad::CommandFailedError, "execution failed: #{cmd.join ' '}"
62
- # end
63
- # end
64
- # def set name, val = nil, &b
65
- # rt.set name, val, &b
66
- # end
67
- # def rt
68
- # @rt ||= Rake::RemoteTask
69
- # end
70
- #
71
- # def target_hosts
72
- # if hosts = ENV["HOSTS"] then
73
- # hosts.strip.gsub(/\s+/, '').split(",")
74
- # elsif options[:single]
75
- # @roles = {}; @roles[:app] = {}
76
- # @roles[:app][options[:single]] = options[:single]
77
- # roles = Rake::RemoteTask.hosts_for(@roles)
78
- # else
79
- # roles = options[:roles]
80
- # roles ? Rake::RemoteTask.hosts_for(roles) : Rake::RemoteTask.all_hosts
81
- # end
82
- # end
83
- # end
@@ -1,199 +0,0 @@
1
- =begin rdoc
2
- Application
3
- This handles user interaction
4
- =end
5
- module PoolParty
6
- class Application
7
- class << self
8
- attr_accessor :verbose, :options
9
-
10
- # The application options
11
- def options(opts={})
12
- @options ||= make_options(opts)
13
- end
14
- # Make the options with the config_file overrides included
15
- # Default config file assumed to be at config/config.yml
16
- def make_options(opts={})
17
- loading_options = opts.delete(:optsparse) || {}
18
- loading_options.merge!( opts || {})
19
-
20
- load_options!(loading_options) # Load command-line options
21
- config_file_location = (default_options[:config_file] || opts[:config_file])
22
-
23
- # If the config_file options are specified and not empty
24
- unless config_file_location.nil? || config_file_location.empty?
25
- require "yaml"
26
- # Try loading the file if it exists
27
- filedata = File.open("#{config_file_location}").read if File.file?("#{config_file_location}")
28
- default_options.merge!( YAML.load(filedata) ) if filedata rescue ""
29
- end
30
- # We want the command-line to overwrite the config file
31
- default_options.merge!(local_user_data) unless local_user_data.nil?
32
- OpenStruct.new(default_options)
33
- end
34
-
35
- # Load options via commandline
36
- def load_options!(opts={})
37
- require 'optparse'
38
- OptionParser.new do |op|
39
- op.banner = opts[:banner] if opts[:banner]
40
- op.on('-A key', '--access-key key', "Ec2 access key (ENV['AWS_ACCESS_KEY'])") { |key| default_options[:access_key] = key }
41
- op.on('-S key', '--secret-access-key key', "Ec2 secret access key (ENV['AWS_SECRET_ACCESS'])") { |key| default_options[:secret_access_key] = key }
42
- op.on('-I ami', '--image-id id', "AMI instance (default: 'ami-40bc5829')") {|id| default_options[:ami] = id }
43
- op.on('-k keypair', '--keypair name', "Keypair name (ENV['KEYPAIR_NAME'])") { |key| default_options[:keypair] = key }
44
- op.on('-b bucket', '--bucket bucket', "Application bucket") { |bucket| default_options[:shared_bucket] = bucket }
45
- # //THIS IS WHERE YOU LEFT OFF
46
- op.on('-D working directory', '--dir dir', "Working directory") { |d| default_options[:working_directory] = d }
47
-
48
- op.on('--ec2-dir dir', "Directory with ec2 data (default: '~/.ec2')") {|id| default_options[:ec2_dir] = id }
49
- op.on('-r names', '--services names', "Monitored services (default: '')") {|id| default_options[:services] = id }
50
- op.on('-c file', '--config-file file', "Config file (default: '')") {|file| default_options[:config_file] = file }
51
- op.on('-l plugin_dir', '--plugin-dir dir', "Plugin directory (default: '')") {|file| default_options[:plugin_dir] = file }
52
- op.on('-p port', '--host_port port', "Run on specific host_port (default: 7788)") { |host_port| default_options[:host_port] = host_port }
53
- op.on('-m monitors', '--monitors names', "Monitor instances using (default: 'web,memory,cpu')") {|s| default_options[:monitor_load_on] = s }
54
- op.on('-o port', '--client_port port', "Run on specific client_port (default: 7788)") { |client_port| default_options[:client_port] = client_port }
55
- op.on('-O os', '--os os', "Configure for os (default: ubuntu)") { |os| default_options[:os] = os }
56
- op.on('-e env', '--environment env', "Run on the specific environment (default: development)") { |env| default_options[:environment] = env }
57
- op.on('-a address', '--public-ip address', "Associate this public address with the master node") {|s| default_options[:public_ip] = s}
58
- op.on('-s size', '--size size', "Run specific sized instance") {|s| default_options[:size] = s}
59
- op.on('-a name', '--name name', "Application name") {|n| default_options[:app_name] = n}
60
- op.on('-u username', '--username name', "Login with the user (default: root)") {|s| default_options[:user] = s}
61
- op.on('-d user-data','--user-data data', "Extra data to send each of the instances (default: "")") { |data| default_options[:user_data] = data.to_str }
62
- op.on('-i', '--install-on-boot', 'Install the PoolParty and custom software on boot (default: false)') {|b| default_options[:install_on_load] = true}
63
- op.on('-t seconds', '--polling-time', "Time between polling in seconds (default 50)") {|t| default_options[:polling_time] = t }
64
- op.on('-v', '--[no-]verbose', 'Run verbosely (default: false)') {|v| default_options[:verbose] = true}
65
- op.on('-n number', '--minimum-instances', "The minimum number of instances to run at all times (default 1)") {|i| default_options[:minimum_instances] = i.to_i}
66
- op.on('-x number', '--maximum-instances', "The maximum number of instances to run (default 3)") {|x| default_options[:maximum_instances] = x.to_i}
67
-
68
- op.on_tail("-V", "Show version") do
69
- puts Application.version
70
- exit
71
- end
72
- op.on_tail("-h", "-?", "Show this message") do
73
- puts op
74
- exit
75
- end
76
- end.parse!(opts[:argv] ? opts.delete(:argv) : ARGV.dup)
77
- end
78
-
79
- # Basic default options
80
- # All can be overridden by the command line
81
- # or in a config.yml file
82
- def default_options
83
- @default_options ||= {
84
- :app_name => "application_name",
85
- :host_port => 80,
86
- :client_port => 8001,
87
- :environment => 'development',
88
- :verbose => false,
89
- :logging => true,
90
- :size => "m1.small",
91
- :polling_time => "30.seconds",
92
- :user_data => "",
93
- :heavy_load => 0.80,
94
- :light_load => 0.15,
95
- :minimum_instances => 2,
96
- :maximum_instances => 4,
97
- :public_ip => "",
98
- :access_key => ENV["AWS_ACCESS_KEY"],
99
- :secret_access_key => ENV["AWS_SECRET_ACCESS"],
100
- :config_file => if ENV["CONFIG_FILE"] && !ENV["CONFIG_FILE"].empty?
101
- ENV["CONFIG_FILE"]
102
- elsif File.file?("config/config.yml")
103
- "config/config.yml"
104
- else
105
- nil
106
- end,
107
- :username => "root",
108
- :ec2_dir => (ENV["EC2_HOME"].nil? || ENV["EC2_HOME"].empty?) ? "~/.ec2" : ENV["EC2_HOME"],
109
- :keypair => (ENV["KEYPAIR_NAME"].nil? || ENV["KEYPAIR_NAME"].empty?) ? File.basename(`pwd`).strip : ENV["KEYPAIR_NAME"],
110
- :ami => 'ami-44bd592d',
111
- :shared_bucket => "",
112
- :expand_when => "web < 1.5\n memory > 0.85",
113
- :contract_when => "cpu < 0.20\n memory < 0.10",
114
- :os => "ubuntu",
115
- :plugin_dir => "plugins",
116
- :install_on_load => false,
117
- :working_directory => Dir.pwd
118
- }
119
- end
120
- # Services monitored by Heartbeat
121
- def master_managed_services
122
- "cloud_master_takeover"
123
- end
124
- alias_method :managed_services, :master_managed_services
125
- def launching_user_data
126
- hash_to_launch_with.to_yaml
127
- end
128
- def hash_to_launch_with
129
- @hash ||= { :polling_time => polling_time,
130
- :access_key => access_key,
131
- :secret_access_key => secret_access_key,
132
- :user_data => user_data,
133
- :keypair => keypair,
134
- :keypair_path => "/mnt"
135
- }
136
- end
137
- def local_user_data
138
- @local_user_data ||= begin
139
- @@timer.timeout(2.seconds) do
140
- YAML.load(open("http://169.254.169.254/latest/user-data").read)
141
- end
142
- rescue Exception => e
143
- {}
144
- end
145
- end
146
- # For testing purposes
147
- def reset!
148
- @options = nil
149
- @local_user_data = nil
150
- end
151
- # Keypair path
152
- # Idiom:
153
- # /Users/username/.ec2/[name]
154
- def keypair_path
155
- options.keypair_path ? options.keypair_path : "#{ec2_dir}/#{keypair_name}"
156
- end
157
- def keypair_name
158
- "id_rsa-#{keypair}"
159
- end
160
- # Are we in development or test mode
161
- %w(development production test).each do |env|
162
- eval <<-EOE
163
- def #{env}?
164
- environment == '#{env}'
165
- end
166
- EOE
167
- end
168
- def environment=(env)
169
- environment = env
170
- end
171
- def maintain_pid_path
172
- "/var/run/pool_maintain.pid"
173
- end
174
- %w(scp_instances_script reconfigure_instances_script).each do |file|
175
- define_method "sh_#{file}" do
176
- File.join(File.dirname(__FILE__), "../..", "config", "#{file}.sh")
177
- end
178
- end
179
- # Standard configuration files
180
- %w(haproxy monit heartbeat heartbeat_authkeys).each do |file|
181
- define_method "#{file}_config_file" do
182
- File.join(File.dirname(__FILE__), "../..", "config", "#{file}.conf")
183
- end
184
- end
185
- def version
186
- PoolParty::Version.string
187
- end
188
- def install_on_load?(bool=false)
189
- options.install_on_load == true || bool
190
- end
191
- # Call the options from the Application
192
- def method_missing(m,*args)
193
- options.methods.include?("#{m}") ? options.send(m,args) : super
194
- end
195
- end
196
-
197
- end
198
-
199
- end