Class: PoolParty::Application
Class Attribute Summary collapse
-
.options(opts = {}) ⇒ Object
The application options.
-
.verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
-
.default_options ⇒ Object
Basic default options All can be overridden by the command line or in a config.yml file.
- .environment=(env) ⇒ Object
- .hash_to_launch_with ⇒ Object
- .install_on_load?(bool = false) ⇒ Boolean
- .keypair_name ⇒ Object
-
.keypair_path ⇒ Object
Keypair path Idiom: /Users/username/.ec2/.
- .launching_user_data ⇒ Object
-
.load_options!(opts = {}) ⇒ Object
Load options via commandline.
- .local_user_data ⇒ Object
- .maintain_pid_path ⇒ Object
-
.make_options(opts = {}) ⇒ Object
Make the options with the config_file overrides included Default config file assumed to be at config/config.yml.
-
.master_managed_services ⇒ Object
(also: managed_services)
Services monitored by Heartbeat.
-
.method_missing(m, *args) ⇒ Object
Call the options from the Application.
-
.reset! ⇒ Object
For testing purposes.
- .version ⇒ Object
Class Attribute Details
.options(opts = {}) ⇒ Object
The application options
11 12 13 |
# File 'lib/poolparty/application.rb', line 11 def @options end |
.verbose ⇒ Object
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/poolparty/application.rb', line 8 def verbose @verbose end |
Class Method Details
.default_options ⇒ Object
Basic default options All can be overridden by the command line or in a config.yml file
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/poolparty/application.rb', line 82 def @default_options ||= { :app_name => "application_name", :host_port => 80, :client_port => 8001, :environment => 'development', :verbose => false, :logging => true, :size => "m1.small", :polling_time => "30.seconds", :user_data => "", :heavy_load => 0.80, :light_load => 0.15, :minimum_instances => 2, :maximum_instances => 4, :public_ip => "", :access_key => ENV["AWS_ACCESS_KEY"], :secret_access_key => ENV["AWS_SECRET_ACCESS"], :config_file => if ENV["CONFIG_FILE"] && !ENV["CONFIG_FILE"].empty? ENV["CONFIG_FILE"] elsif File.file?("config/config.yml") "config/config.yml" else nil end, :username => "root", :ec2_dir => (ENV["EC2_HOME"].nil? || ENV["EC2_HOME"].empty?) ? "~/.ec2" : ENV["EC2_HOME"], :keypair => (ENV["KEYPAIR_NAME"].nil? || ENV["KEYPAIR_NAME"].empty?) ? File.basename(`pwd`).strip : ENV["KEYPAIR_NAME"], :ami => 'ami-44bd592d', :shared_bucket => "", :expand_when => "web < 1.5\n memory > 0.85", :contract_when => "cpu < 0.20\n memory < 0.10", :os => "ubuntu", :plugin_dir => "plugins", :install_on_load => false, :working_directory => Dir.pwd } end |
.environment=(env) ⇒ Object
168 169 170 |
# File 'lib/poolparty/application.rb', line 168 def environment=(env) environment = env end |
.hash_to_launch_with ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/poolparty/application.rb', line 128 def hash_to_launch_with @hash ||= { :polling_time => polling_time, :access_key => access_key, :secret_access_key => secret_access_key, :user_data => user_data, :keypair => keypair, :keypair_path => "/mnt" } end |
.install_on_load?(bool = false) ⇒ Boolean
188 189 190 |
# File 'lib/poolparty/application.rb', line 188 def install_on_load?(bool=false) .install_on_load == true || bool end |
.keypair_name ⇒ Object
157 158 159 |
# File 'lib/poolparty/application.rb', line 157 def keypair_name "id_rsa-#{keypair}" end |
.keypair_path ⇒ Object
Keypair path Idiom:
/Users/username/.ec2/[name]
154 155 156 |
# File 'lib/poolparty/application.rb', line 154 def keypair_path .keypair_path ? .keypair_path : "#{ec2_dir}/#{keypair_name}" end |
.launching_user_data ⇒ Object
125 126 127 |
# File 'lib/poolparty/application.rb', line 125 def launching_user_data hash_to_launch_with.to_yaml end |
.load_options!(opts = {}) ⇒ Object
Load options via commandline
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/poolparty/application.rb', line 36 def (opts={}) require 'optparse' OptionParser.new do |op| op. = opts[:banner] if opts[:banner] op.on('-A key', '--access-key key', "Ec2 access key (ENV['AWS_ACCESS_KEY'])") { |key| [:access_key] = key } op.on('-S key', '--secret-access-key key', "Ec2 secret access key (ENV['AWS_SECRET_ACCESS'])") { |key| [:secret_access_key] = key } op.on('-I ami', '--image-id id', "AMI instance (default: 'ami-40bc5829')") {|id| [:ami] = id } op.on('-k keypair', '--keypair name', "Keypair name (ENV['KEYPAIR_NAME'])") { |key| [:keypair] = key } op.on('-b bucket', '--bucket bucket', "Application bucket") { |bucket| [:shared_bucket] = bucket } # //THIS IS WHERE YOU LEFT OFF op.on('-D working directory', '--dir dir', "Working directory") { |d| [:working_directory] = d } op.on('--ec2-dir dir', "Directory with ec2 data (default: '~/.ec2')") {|id| [:ec2_dir] = id } op.on('-r names', '--services names', "Monitored services (default: '')") {|id| [:services] = id } op.on('-c file', '--config-file file', "Config file (default: '')") {|file| [:config_file] = file } op.on('-l plugin_dir', '--plugin-dir dir', "Plugin directory (default: '')") {|file| [:plugin_dir] = file } op.on('-p port', '--host_port port', "Run on specific host_port (default: 7788)") { |host_port| [:host_port] = host_port } op.on('-m monitors', '--monitors names', "Monitor instances using (default: 'web,memory,cpu')") {|s| [:monitor_load_on] = s } op.on('-o port', '--client_port port', "Run on specific client_port (default: 7788)") { |client_port| [:client_port] = client_port } op.on('-O os', '--os os', "Configure for os (default: ubuntu)") { |os| [:os] = os } op.on('-e env', '--environment env', "Run on the specific environment (default: development)") { |env| [:environment] = env } op.on('-a address', '--public-ip address', "Associate this public address with the master node") {|s| [:public_ip] = s} op.on('-s size', '--size size', "Run specific sized instance") {|s| [:size] = s} op.on('-a name', '--name name', "Application name") {|n| [:app_name] = n} op.on('-u username', '--username name', "Login with the user (default: root)") {|s| [:user] = s} op.on('-d user-data','--user-data data', "Extra data to send each of the instances (default: "")") { |data| [:user_data] = data.to_str } op.on('-i', '--install-on-boot', 'Install the PoolParty and custom software on boot (default: false)') {|b| [:install_on_load] = true} op.on('-t seconds', '--polling-time', "Time between polling in seconds (default 50)") {|t| [:polling_time] = t } op.on('-v', '--[no-]verbose', 'Run verbosely (default: false)') {|v| [:verbose] = true} op.on('-n number', '--minimum-instances', "The minimum number of instances to run at all times (default 1)") {|i| [:minimum_instances] = i.to_i} op.on('-x number', '--maximum-instances', "The maximum number of instances to run (default 3)") {|x| [:maximum_instances] = x.to_i} op.on_tail("-V", "Show version") do puts Application.version exit end op.on_tail("-h", "-?", "Show this message") do puts op exit end end.parse!(opts[:argv] ? opts.delete(:argv) : ARGV.dup) end |
.local_user_data ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/poolparty/application.rb', line 137 def local_user_data @local_user_data ||= begin @@timer.timeout(2.seconds) do YAML.load(open("http://169.254.169.254/latest/user-data").read) end rescue Exception => e {} end end |
.maintain_pid_path ⇒ Object
171 172 173 |
# File 'lib/poolparty/application.rb', line 171 def maintain_pid_path "/var/run/pool_maintain.pid" end |
.make_options(opts = {}) ⇒ Object
Make the options with the config_file overrides included Default config file assumed to be at config/config.yml
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/poolparty/application.rb', line 16 def (opts={}) = opts.delete(:optsparse) || {} .merge!( opts || {}) () # Load command-line options config_file_location = ([:config_file] || opts[:config_file]) # If the config_file options are specified and not empty unless config_file_location.nil? || config_file_location.empty? require "yaml" # Try loading the file if it exists filedata = File.open("#{config_file_location}").read if File.file?("#{config_file_location}") .merge!( YAML.load(filedata) ) if filedata rescue "" end # We want the command-line to overwrite the config file .merge!(local_user_data) unless local_user_data.nil? OpenStruct.new() end |
.master_managed_services ⇒ Object Also known as: managed_services
Services monitored by Heartbeat
121 122 123 |
# File 'lib/poolparty/application.rb', line 121 def master_managed_services "cloud_master_takeover" end |
.method_missing(m, *args) ⇒ Object
Call the options from the Application
192 193 194 |
# File 'lib/poolparty/application.rb', line 192 def method_missing(m,*args) .methods.include?("#{m}") ? .send(m,args) : super end |
.reset! ⇒ Object
For testing purposes
147 148 149 150 |
# File 'lib/poolparty/application.rb', line 147 def reset! @options = nil @local_user_data = nil end |