bash -c ' # This is the ubuntu-10.04-cluster_chef script from infochimps, which # is based on the ubuntu-10.04-gems script from opscode, but it # * installs ruby 1.9.2, not 1.8.7 using the system ruby # * upgrades rubygems rather than installing from source # * pushes the node identity into the first-boot.json # * installs the chef-client service and kicks off the first run of chef set -e <%= (@config[:verbosity].to_i > 1 ? 'set -v' : '') %> mkdir -p /tmp/knife-bootstrap chmod 700 /tmp/knife-bootstrap cd /tmp/knife-bootstrap <%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%> eval `cat /etc/lsb-release ` export DEBIAN_FRONTEND=noninteractive # source for sun java if you want to install it later apt-get install -y python-software-properties add-apt-repository ppa:ferramroberto/java apt-get -y update if [ ! -f /usr/bin/chef-client ]; then echo -e "`date` \n\n**** \n**** apt update:\n****\n" apt-get update apt-get -y upgrade echo -e "`date` \n\n**** \n**** Installing base packages:\n****\n" apt-get install -y build-essential wget ruby1.9.1 ruby1.9.1-dev runit zlib1g-dev libssl-dev openssl libcurl4-openssl-dev libreadline6-dev libyaml-dev if ruby -e "exit(%x{gem --version} < \"1.6.2\" ? 0 : -1 )" ; then echo -e "`date` \n\n**** \n**** Updating rubygems:\n****\n" gem update --system # screw you rubygems for foo in /usr/lib/ruby/site_ruby/*/rubygems/deprecate.rb ; do sudo sed -i.bak 's!@skip ||= false!true!' "$foo" ; done fi echo -e "`date` \n\n**** \n**** Installing chef:\n****\n" gem install ohai --no-rdoc --no-ri gem install chef --no-rdoc --no-ri <%= bootstrap_version_string %> gem install --no-rdoc --no-ri bundler pry cheat else # no chef-client echo -e "`date` \n\n**** \n**** Chef is present -- skipping apt/ruby/chef installation\n****\n" fi # fix a bug in chef that prevents debugging template errors bad_template_file='/usr/lib/ruby/gems/1.9.1/gems/chef-0.10.4/lib/chef/mixin/template.rb' if echo "0505c482b8b0b333ac71bbc8a1795d19 $bad_template_file" | md5sum -c - 2>/dev/null ; then curl https://github.com/mrflip/chef/commit/655a1967253a8759afb54f30b818bbcb7c309198.patch | sudo patch $bad_template_file fi echo -e "`date` \n\n**** \n**** Knifing in the chef client config files:\n****\n" mkdir -p /etc/chef <%- if @config[:client_key] %> ( cat <<'EOP' <%= @config[:client_key] %> EOP ) > /tmp/knife-bootstrap/client.pem awk NF /tmp/knife-bootstrap/client.pem > /etc/chef/client.pem <%- else %> ( cat <<'EOP' <%= validation_key %> EOP ) > /tmp/knife-bootstrap/validation.pem awk NF /tmp/knife-bootstrap/validation.pem > /etc/chef/validation.pem <%- end %> echo -e "`date` \n\n**** \n**** Nuking our temp files:\n****\n" cd /tmp # rm -rf /tmp/knife-bootstrap echo -e "`date` \n\n**** \n**** Creating chef client script:\n****\n" ( cat <<'EOP' <%= config_content %> <%= @config[:node].chef_client_script_content %> EOP ) > /etc/chef/client.rb ( cat <<'EOP' <%= { "run_list" => @run_list, "cluster_name" => @config[:node].cluster_name, "facet_name" => @config[:node].facet_name, "facet_index" => @config[:node].facet_index }.to_json %> EOP ) > /etc/chef/first-boot.json echo -e "`date` \n\n**** \n**** Adding chef client runit scripts:\n****\n" (service chef-client stop >/dev/null 2>&1 ; sleep 1 ; killall chef-client 2>/dev/null) || true mkdir -p /var/log/chef /var/chef /etc/service /etc/sv/chef-client/{log/main,supervise} cat > /etc/sv/chef-client/log/run < /etc/sv/chef-client/run <&1 exec /usr/bin/env chef-client -i 43200 -s 20 -L /var/log/chef/client.log EOF chmod +x /etc/sv/chef-client/log/run /etc/sv/chef-client/run ln -nfs /usr/bin/sv /etc/init.d/chef-client service chef-client stop || true <%- if (@config[:bootstrap_runs_chef_client].to_s == 'true') || (@chef_config.knife[:bootstrap_runs_chef_client].to_s == 'true') %> echo -e "`date` \n\n**** \n**** First run of chef:\n****\n" set -e <%= start_chef %> set +e <%- end %> echo -e "`date` \n\n**** \n**** Cleanup:\n****\n" updatedb echo -e "`date` \n\n**** \n**** Enabling chef client service:\n****\n" ln -nfs /etc/sv/chef-client /etc/service/chef-client service chef-client start echo -e "`date` \n\n**** \n**** Cluster Chef client bootstrap complete\n****\n" ' || echo "Chef bootstrap failed!"