=begin rdoc BootStrapper is contains the basic files that need to be uploaded to a new instance and the first commands that are run to set up a base PoolParty enviornment. This includes things like ensuring that ruby, rubygems, and poolparty are installed, and then start the monitor. =end require "#{::File.dirname(__FILE__)}/../net/remoter/connections" # Provide a very simple provisioner with as few dependencies as possible module PoolParty module Provision class BootStrapper include ::PoolParty::Remote # List of gems that are default to install 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 json activesupport grempe-amazon-ec2 ohai chef ruby-openid adamwiggins-rest-client rack thin logging ruby2ruby ) end # Default options for the boot_strapper @defaults = ::PoolParty::Default.dsl_options.merge({ :full_keypair_path => "#{ENV["AWS_KEYPAIR_NAME"]}" || "~/.ssh/id_rsa", :installer => 'apt-get', :dependency_resolver => 'chef' }) class < "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 # The commands to setup a PoolParty enviornment def default_commands pack_the_dependencies ::FileUtils.rm_rf "#{cloud.tmp_path}/dependencies/gems/cache" rsync "#{cloud.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_template /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", "gem sources -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 --'", "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 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 end end end