/
ubuntu10.04-ironfan.erb
executable file
·173 lines (142 loc) · 6.66 KB
/
ubuntu10.04-ironfan.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
78
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
117
118
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
bash <<'EOF' || echo "Chef bootstrap failed!"
# This is the ubuntu natty bootstrap script from infochimps' ironfan. It is
# based on opscode's bootstrap script, with the following important differences:
#
# * installs ruby 1.9.2 (not 1.8.7) from source
# * 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' : '') %>
RUBY_VERSION=1.9.2-p290
CHEF_VERSION=<%= bootstrap_version_string.gsub(/.*[\s=]/,"") %>
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
date > /etc/box_build_time
echo -e "`date` \n\n**** \n**** apt update:\n****\n"
apt-get --force-yes -y update
apt-get --force-yes -y upgrade
echo -e "`date` \n\n**** \n**** Installing base packages:\n****\n"
apt-get --force-yes -y install build-essential make wget curl runit zlib1g-dev libssl-dev openssl libcurl4-openssl-dev libxml2-dev libxslt-dev libyaml-dev libreadline6 libreadline6-dev
apt-get --force-yes -y install runit-services
apt-get clean
# do not trust the ubuntu chef package
rm -f /etc/init.d/chef-client || true
apt-get remove -y --force-yes chef ruby1.8-dev libjson-ruby1.8 libmixlib-authentication-ruby1.8 ohai libmixlib-log-ruby1.8 libmime-types-ruby librestclient-ruby1.8 ruby1.8 ruby liberubis-ruby1.8 libsystemu-ruby1.8 libohai-ruby libuuidtools-ruby1.8 libhighline-ruby1.8 libabstract-ruby1.8 libmixlib-config-ruby1.8 rubygems1.8 libbunny-ruby1.8 libchef-ruby1.8 libmixlib-cli-ruby1.8 libyajl-ruby libmoneta-ruby1.8 libohai-ruby1.8 libextlib-ruby1.8 || true
# apt-get remove -y --force-yes --purge myproxy globus-core condor nis autofs myproxy-server globus-proxy-utils globus-repository-natty globus-gridftp-server-progs globus-gass-copy-progs globus-simple-ca globus-gsi-cert-utils-progs || true
sudo apt-get autoremove -y --force-yes || true
if [ ! -f /usr/bin/chef-client ]; then
echo -e "`date` \n\n**** \n**** Installing ruby version ${RUBY_VERSION}:\n****\n"
wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-${RUBY_VERSION}.tar.gz
tar xzf ruby-${RUBY_VERSION}.tar.gz
cd ruby-${RUBY_VERSION}
./configure --with-ruby-version=${RUBY_VERSION} --prefix=/usr --program-suffix=${RUBY_VERSION}
make -j2
make install
sudo update-alternatives --remove-all gem && true
update-alternatives \
--install /usr/bin/ruby ruby /usr/bin/ruby${RUBY_VERSION} 400 \
--slave /usr/bin/ri ri /usr/bin/ri${RUBY_VERSION} \
--slave /usr/bin/irb irb /usr/bin/irb${RUBY_VERSION} \
--slave /usr/bin/erb erb /usr/bin/erb${RUBY_VERSION} \
--slave /usr/bin/gem gem /usr/bin/gem${RUBY_VERSION} \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby${RUBY_VERSION}.1
if ruby -e "exit(%x{gem --version} < \"1.6.2\" ? 0 : -1 )" ; then
echo -e "`date` \n\n**** \n**** Updating rubygems:\n****\n"
# screw you Debian
REALLY_GEM_UPDATE_SYSTEM=1 gem update --system
# screw you rubygems
for foo in /usr/lib/ruby/site_ruby/*/rubygems/deprecate.rb ; do
# Don't have to be any such deprecations, in which case $foo won't exist
[ -f "$foo" ] && 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 %>
# gems needed for the client.rb or so generically useful you want them at hand
gem install --no-rdoc --no-ri extlib bundler json right_aws pry fog
else # no chef-client
echo -e "`date` \n\n**** \n**** Chef is present -- skipping apt/ruby/chef installation\n****\n"
fi # end ruby+chef install
# fix a bug in chef that prevents debugging template errors
# will not work with --prerelease but that's OK hopefully opscode patches this crap soon
bad_template_file="/usr/lib/ruby/gems/${RUBY_VERSION}/gems/chef-${CHEF_VERSION}/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 %>
<% if @chef_config[:encrypted_data_bag_secret] -%>
(
cat <<'EOP'
<%= encrypted_data_bag_secret %>
EOP
) > /tmp/encrypted_data_bag_secret
awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret
rm /tmp/encrypted_data_bag_secret
<% 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 <<'EOP'
#!/bin/bash
exec svlogd -tt ./main
EOP
cat > /etc/sv/chef-client/run <<'EOP'
#!/bin/bash
exec 2>&1
exec /usr/bin/env chef-client -i 43200 -s 20 -L /var/log/chef/client.log
EOP
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 >/dev/null 2>&1 || 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"
# make locate work good
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"
EOF