Last active
December 29, 2015 06:19
-
-
Save os6sense/7628069 to your computer and use it in GitHub Desktop.
Bootstrap chef onto a new system. Based on Jo Liss's bootstrap http://www.opinionatedprogrammer.com/2011/06/chef-solo-tutorial-managing-a-single-server-with-chef/. Run sh depoly.sh user@ipaddress_or_host to deploy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: ./deploy.sh [host] | |
# e.g. sh deploy user@123.212.11.14 | |
host="$1" | |
# The host key might change when we instantiate a new VM, so | |
# we remove (-R) the old host key from known_hosts | |
ssh-keygen -R "${host#*@}" 2> /dev/null | |
tar cj . | ssh -o 'StrictHostKeyChecking no' "$host" ' | |
sudo rm -rf ~/chef && | |
mkdir ~/chef && | |
cd ~/chef && | |
tar xj && | |
sudo bash install.sh' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Bootstrap chef onto a vanilla server. This runs as root on the server. | |
# This must be the location where chef-solo is installer OR | |
# IF it is installed via this bootstrap process, where it will | |
# be installed via "gem install chef" | |
chef_binary=/usr/local/bin/chef-solo | |
# chef requires ruby to install - since the purpose of this script | |
# is to bootstrap chef, it is suggested that the version of ruby installed | |
# is tailored to match that which is required for any deployed apps on this server. | |
ruby_version_full="ruby-2.0.0-p353" | |
if ! test -f "$chef_binary"; then | |
ruby_version_major=${ruby_version_full:5:3} | |
export DEBIAN_FRONTEND=noninteractive | |
aptitude update && | |
apt-get -o Dpkg::Options::="--force-confnew" \ | |
--force-yes -fuy dist-upgrade && | |
if ! echo `ruby -v` | grep -q $ruby_version_major ; then | |
aptitude install -y build-essential openssl libreadline6 libreadline6-dev \ | |
curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev automake \ | |
autotools-dev gcc gcc-4.8 libasan0 libatomic1 libc-dev-bin \ | |
libgcc-4.8-dev libgomp1 libitm1 libquadmath0 libtinfo-dev \ | |
libtsan0 libxslt1.1 linux-libc-dev m4 manpages-dev \ | |
libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev | |
aptitude install -y git | |
if ! test -f "/root/chef/${ruby_version_full}.tar.gz"; then | |
wget http://cache.ruby-lang.org/pub/ruby/${ruby_version_major}/${ruby_version_full}.tar.gz | |
fi | |
tar xvzf ${ruby_version_full}.tar.gz | |
cd ${ruby_version_full} | |
./configure --disable-install-doc | |
make | |
sudo make install | |
fi | |
sudo gem install --no-rdoc --no-ri chef | |
fi && | |
"$chef_binary" -c solo.rb -j solo.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"run_list": ["recipe[op::swapfile]", "recipe[op::default]"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root = File.absolute_path(File.dirname(__FILE__)) | |
file_cache_path root | |
cookbook_path root + '/cookbooks' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# swapfile.rb - direct copy of Jo Liss's http://www.opinionatedprogrammer.com/2011/07/creating-a-swap-file-with-chef/ | |
# This comes in very handy in instances where you have a low memory VM - I even had issues with a 1GB droplet and building passsenger as part of a chef deploy hence it is recommended. Place in cookbooks/XX/recipies/swapfile.rb. | |
script 'create swapfile' do | |
interpreter 'bash' | |
not_if { File.exists?('/var/swapfile') } | |
code <<-eof | |
dd if=/dev/zero of=/var/swapfile bs=1M count=2048 && | |
chmod 600 /var/swapfile && | |
mkswap /var/swapfile | |
eof | |
end | |
mount '/dev/null' do # swap file entry for fstab | |
action :enable # cannot mount; only add to fstab | |
device '/var/swapfile' | |
fstype 'swap' | |
end | |
script 'activate swap' do | |
interpreter 'bash' | |
code 'swapon -a' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment