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.
Instance Attribute Summary collapse
-
#cloud_name ⇒ Object
readonly
Returns the value of attribute cloud_name.
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
#are_any_nodes_exceeding_minimum_runtime?, #are_too_few_instances_running?, #are_too_many_instances_running?, available, #commands, #execute!, #list_of_instances, #list_of_nodes_exceeding_minimum_runtime, #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.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 64 def initialize(host, opts={}, &block) self.class.defaults.merge(opts).to_instance_variables(self) @target_host = host @cloud = opts[:cloud] @cloud_name = @cloud.name 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
54 55 56 57 58 59 60 61 62 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 54 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.
49 50 51 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 49 def defaults @defaults end |
Instance Attribute Details
#cloud_name ⇒ Object (readonly)
Returns the value of attribute cloud_name.
51 52 53 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 51 def cloud_name @cloud_name end |
Class Method Details
.class_commands ⇒ Object
82 83 84 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 82 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 36 37 38 39 40 41 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 15 def self.gem_list # auser-dslify # auser-parenting @gem_list ||= %w( logging rake xml-simple net-ssh net-sftp net-scp net-ssh-gateway highline flexmock lockfile rubigen json grempe-amazon-ec2 ohai chef ruby-openid auser-rest-client rack thin logging ruby2ruby extlib ) end |
Instance Method Details
#after_bootstrap ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 165 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
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 130 def default_commands pack_the_dependencies ::FileUtils.rm_rf "#{cloud.tmp_path}/dependencies/gems/cache" rsync "#{cloud.tmp_path}/dependencies", '/var/poolparty', ['-v', '-a', '--delete'] commands << [ "mkdir -p /etc/poolparty", "echo #{cloud.name} > /etc/poolparty/cloud_name", "echo #{cloud.pool.name}>/etc/poolparty/pool_name", "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_template /etc/poolparty", "#{installer} update", "#{installer} install -y ruby ruby1.8-dev irb libopenssl-ruby1.8 build-essential wget", #optional, but nice to have "tar -zxvf packages/rubygems-1.3.4.tgz && cd rubygems-1.3.4 && ruby setup.rb --no-ri --no-rdoc && ln -sfv /usr/bin/gem1.8 /usr/bin/gem && cd ../ && rm -rf rubygems-1.3.1*", "gem source --add http://gems.github.com", "gem source -a http://gems.opscode.com", "cd /var/poolparty/dependencies/gems/", "gem install --no-rdoc --no-ri *.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/#{keypair_name}", # "god -c /etc/poolparty/monitor.god", "mkdir -p /var/log/poolparty/", "echo '-- Starting monitor_rack --'", # NOTE: if someone has an old version of thin/rack on their system, this will fail silently and never finish bootstrapping "ps aux | grep thin | grep -v grep | awk '{print $2}' | xargs kill -9; 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", "tail -n 20 /var/log/poolparty/monitor.log", '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
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 120 121 122 123 124 125 126 127 |
# File 'lib/poolparty/provision/boot_strapper.rb', line 87 def pack_the_dependencies # Add the keypair to the instance... shudder ::Suitcase::Zipper.add(keypair, "keys") ::Suitcase::Zipper.add_content_as(Default.keys_in_yaml, "ppkeys", "keys") edge_pp_gem = Dir["#{Default.vendor_path}/../pkg/*poolparty*gem"].pop # Use the locally built poolparty gem if it is available if edge_pp_gem 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, :gem_location => "#{cloud.tmp_path}/trash/dependencies", :search_paths => ["#{Default.vendor_path}/../pkg"] ::Suitcase::Zipper.packages( "http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz", "#{cloud.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("#{cloud.tmp_path}/trash/dependencies/cache", "gems") ::Suitcase::Zipper.add("#{::File.join(File.dirname(__FILE__), '..', 'templates', 'gemrc_template' )}", "etc/poolparty") instances = @cloud.nodes(:status => "running") + [@cloud.started_instance] # ::Suitcase::Zipper.add_content_as( # instances.flatten.compact.to_json, # "neighborhood.json", "/etc/poolparty" # ) ::Suitcase::Zipper.build_dir!("#{cloud.tmp_path}/dependencies") ::Suitcase::Zipper.flush! # ::FileUtils.rm_rf "#{Default.tmp_path}/trash" end |