Skip to content

Instantly share code, notes, and snippets.

@karmi
Last active November 15, 2017 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karmi/10019159 to your computer and use it in GitHub Desktop.
Save karmi/10019159 to your computer and use it in GitHub Desktop.
Basic recipe to deploy Ruby+Elasticsearch applications with Chef
# Installation
# ------------
#
# $ ssh -i ~/.ssh/yourkey.pem user@ec2-12-34-56-78.compute-1.amazonaws.com
#
# $ sudo apt-get install curl -y
# $ curl -# -L http://www.opscode.com/chef/install.sh | sudo bash -s --
#
# $ time curl https://gist.githubusercontent.com/karmi/10019159/raw/chef-base-ruby-elasticsearch-server.rb | sudo chef-apply -s
STDOUT.sync = true
STDERR.sync = true
# ----- Packages and Tools --
bash "apt update" do
code "apt-get update"
end
%w| build-essential
make
bison
zlib1g-dev
libopenssl-ruby1.9.1
libcurl4-openssl-dev
libssl-dev
libyaml-dev
libxml2-dev libxslt1-dev
libreadline-dev
libncurses5-dev
file
sqlite3 libsqlite3-dev
ruby1.9.3
curl
vim
git
htop |.each { |name| package name }
# ----- Elasticsearch -------
package "openjdk-7-jre-headless"
remote_file "/tmp/elasticsearch-1.1.0.deb" do
source "https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.0.deb"
checksum "2cecb08a388948c3c6300ca56e0aad11796c3109"
action :create_if_missing
end
dpkg_package "elasticsearch-1.1.0.deb" do
package_name "elasticsearch"
source "/tmp/elasticsearch-1.1.0.deb"
end
bash "set ES_HEAP_SIZE" do
code "echo 'ES_HEAP_SIZE=256m' >> /etc/default/elasticsearch"
not_if "grep '^ES_HEAP_SIZE=256m' /etc/default/elasticsearch"
end
bash "configure Elasticsearch" do
code "echo 'cluster.name: ruby-elasticsearch' >> /etc/elasticsearch/elasticsearch.yml"
not_if "grep '^cluster.name: ruby-elasticsearch' /etc/elasticsearch/elasticsearch.yml"
end
service "elasticsearch" do
action [ :enable, :start ]
end
# ----- Redis ---------------
package "redis-server"
# ----- The Application -----
bash "install Bundler" do
code "gem install bundler"
not_if "gem list | grep bundler"
end
# ----- Monit -----
package 'monit'
bash "enable Monit httpd" do
code <<-CONTENT.gsub(/^\s*/, '')
echo '
set daemon 60
set httpd port 2812 and
use address localhost
allow localhost
' >> /etc/monit/monitrc
CONTENT
not_if do
File.read('/etc/monit/monitrc') =~ /^set httpd port 2812/
end
end
file "/etc/monit/conf.d/application.conf" do
content <<-MONITRC
MONITRC
end
bash "reload monit" do
code "service monit reload"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment