Class: PoolParty::Provision::BootStrapper
- Includes:
- Remote
- Defined in:
- lib/poolparty/provision/boot_strapper.rb
Class Attribute Summary collapse
-
.defaults ⇒ Object
readonly
Returns the value of attribute defaults.
Class Method Summary collapse
- .class_commands ⇒ Object
-
.gem_list ⇒ Object
List of gems that are default to install.
Instance Method Summary collapse
- #after_bootstrap ⇒ Object
-
#default_commands ⇒ Object
The commands to setup a PoolParty enviornment.
-
#initialize(host, opts = {}, &block) ⇒ BootStrapper
constructor
A new instance of BootStrapper.
-
#method_missing(m, *a, &block) ⇒ Object
In case the method is being called on ourself, let’s check the defaults hash to see if it’s available there.
-
#pack_the_dependencies ⇒ Object
Collect all the bootstrap files that will be uploaded to the remote instances.
Methods included from Remote
#_nodes, #are_any_nodes_exceeding_minimum_runtime?, #are_too_few_instances_running?, #are_too_many_instances_running?, #commands, #execute!, #is_master_running?, #list_of_instances, #list_of_nodes_exceeding_minimum_runtime, #master, #netssh, #nodes, #remote_rsync_command, #remote_ssh_array, #remote_ssh_string, #rsync, #rsync_command, #rsync_storage_files_to, #rsync_storage_files_to_command, #rsync_to, #rsync_to_command, #run_command_on, #run_command_on_command, #run_command_on_instance_number, #run_local, #run_remote, #scp_array, #scp_to_command, #simplest_run_remote, #ssh_array, #ssh_command, #ssh_into, #ssh_into_instance_number, #ssh_options, #ssh_string, #target_host
Methods included from PoolParty::Pinger
Constructor Details
#initialize(host, opts = {}, &block) ⇒ BootStrapper
Returns a new instance of BootStrapper.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 57 def initialize(host, opts={}, &block) self.class.defaults.merge(opts).to_instance_variables(self) @target_host = host @cloud = opts[:cloud] instance_eval &block if block @cloud.call_before_bootstrap_callbacks if @cloud default_commands dputs "Starting bootstrapping process on #{host}" execute! @cloud.call_after_bootstrap_callbacks if @cloud after_bootstrap dputs "Bootstrapping complete on #{host}" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &block) ⇒ Object
In case the method is being called on ourself, let’s check the defaults hash to see if it’s available there
47 48 49 50 51 52 53 54 55 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 47 def method_missing(m,*a,&block) if self.class.defaults.has_key?(m) self.class.defaults[m] elsif @cloud @cloud.send m, *a, &block else super end end |
Class Attribute Details
.defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
43 44 45 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 43 def defaults @defaults end |
Class Method Details
.class_commands ⇒ Object
74 75 76 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 74 def self.class_commands @class_commands ||= [] end |
.gem_list ⇒ Object
List of gems that are default to install
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 15 def self.gem_list @gem_list ||= %w( logging rake xml-simple net-ssh net-sftp net-scp net-ssh-gateway highline json activesupport grempe-amazon-ec2 ohai chef auser-dslify auser-parenting adamwiggins-rest-client rack thin ) end |
Instance Method Details
#after_bootstrap ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 154 def after_bootstrap # thin_cmd = "thin -R /etc/poolparty/monitor.ru start -p 8642 --daemonize --pid /var/run/poolparty/monitor.pid --log /var/log/poolparty/monitor.log --environment production --chdir /var/poolparty" #TODO --user poolparty --group poolparty # vputs "thin_cmd = #{thin_cmd}" # curl_put = "curl -i -XPUT -d'{}' http://localhost:8642/stats_monitor" # execute! [ thin_cmd, "sleep 10", curl_put ] # execute! ["sleep 5", curl_put] end |
#default_commands ⇒ Object
The commands to setup a PoolParty enviornment
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 119 def default_commands pack_the_dependencies ::FileUtils.rm_rf "#{Default.tmp_path}/dependencies/gems/cache" rsync "#{Default.tmp_path}/dependencies", '/var/poolparty' commands << [ "mkdir -p /etc/poolparty", "mkdir -p /var/log/poolparty", "groupadd -f poolparty", # "useradd poolparty --home-dir /var/poolparty --groups poolparty --create-home", 'cd /var/poolparty/dependencies', "cp /var/poolparty/dependencies/etc/poolparty/gemrc /etc/poolparty", "#{installer} update", "#{installer} install -y ruby ruby1.8-dev libopenssl-ruby1.8 build-essential wget", #optional, but nice to have "tar -zxvf packages/rubygems-1.3.1.tgz", "cd rubygems-1.3.1", "ruby setup.rb --no-ri --no-rdoc", "ln -sfv /usr/bin/gem1.8 /usr/bin/gem", #TODO: check if this is really needed "cd ../ && rm -rf rubygems-1.3.1*", "gem source --add http://gems.github.com", "cd /var/poolparty/dependencies/gems/", "gem install --no-rdoc --no-ri -y *.gem", "cd /var/poolparty/dependencies", "cp /var/poolparty/dependencies/etc/poolparty/* /etc/poolparty/", 'touch /var/poolparty/POOLPARTY.PROGRESS', "mkdir -p /root/.ssh", "cp /var/poolparty/dependencies/keys/* /root/.ssh/", "chmod 600 /root/.ssh/#{::File.basename(@cloud.keypair.full_filepath)}", # "god -c /etc/poolparty/monitor.god", "mkdir -p /var/log/poolparty/", "thin -R /etc/poolparty/monitor.ru -p 8642 --pid /var/run/stats_monitor.pid --daemon -l /var/log/poolparty/monitor.log start 2>/dev/null", 'echo "bootstrap" >> /var/poolparty/POOLPARTY.PROGRESS'] commands << self.class.class_commands unless self.class.class_commands.empty? end |
#pack_the_dependencies ⇒ Object
Collect all the bootstrap files that will be uploaded to the remote instances
79 80 81 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 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 79 def pack_the_dependencies # Add the keypair to the instance... shudder ::Suitcase::Zipper.add(keypair, "keys") # Use the locally built poolparty gem if it is availabl if edge_pp_gem = Dir["#{Default.vendor_path}/../pkg/*poolparty*gem"].pop puts "using edge poolparty: #{::File.(edge_pp_gem)}" ::Suitcase::Zipper.add(edge_pp_gem, 'gems') else vputs "using gem auser-poolparty. use rake build to use edge" self.class.gem_list << 'auser-poolparty' end # Add the gems to the suitcase puts "Adding default gem dependencies" ::Suitcase::Zipper.gems self.class.gem_list, "#{Default.tmp_path}/trash/dependencies" ::Suitcase::Zipper.packages( "http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz", "#{Default.tmp_path}/trash/dependencies/packages") # ::Suitcase::Zipper.add("templates/") ::Suitcase::Zipper.add("#{::File.dirname(__FILE__)}/../templates/monitor.ru", "/etc/poolparty/") ::Suitcase::Zipper.add("#{::File.dirname(__FILE__)}/../templates/monitor.god", "/etc/poolparty/") ::Suitcase::Zipper.add("#{Default.tmp_path}/trash/dependencies/cache", "gems") ::Suitcase::Zipper.add("#{::File.join(File.dirname(__FILE__), '..', 'templates', 'gemrc' )}", "etc/poolparty") instances = @cloud.nodes(:status => "running") + [@cloud.started_instance] ::Suitcase::Zipper.add_content_as( {:instances => instances.flatten.compact}.to_json, "neighborhood.json", "/etc/poolparty") ::Suitcase::Zipper.build_dir!("#{Default.tmp_path}/dependencies") ::Suitcase::Zipper.flush! # ::FileUtils.rm_rf "#{Default.tmp_path}/trash" end |