├── elasticsearch_config ├── test │ └── integration │ │ └── default │ │ ├── bats │ │ └── default.bats │ │ └── serverspec │ │ └── default_spec.rb ├── metadata.rb └── recipes │ └── default.rb ├── consul_config ├── recipes │ ├── fluentd.rb │ ├── nginx.rb │ ├── rails.rb │ ├── fluentd_aggregator.rb │ ├── wordpress.rb │ ├── sidekiq.rb │ └── elasticsearch.rb ├── attributes │ └── sidekiq.rb └── metadata.rb ├── librato-collectd ├── recipes │ ├── _service.rb │ ├── docker.rb │ └── default.rb └── metadata.rb ├── README.md ├── .gitignore ├── fluentd_config ├── metadata.rb └── recipes │ ├── chgrp.rb │ └── default.rb ├── opsworks_ecs ├── templates │ └── default │ │ └── ecs.config.erb └── recipes │ └── setup_ubuntu.rb ├── Berksfile └── Berksfile.lock /elasticsearch_config/test/integration/default/bats/default.bats: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /consul_config/recipes/fluentd.rb: -------------------------------------------------------------------------------- 1 | consul_check_def "fluentd" do 2 | http "http://localhost:24220/api/plugins.json" 3 | interval "30s" 4 | end 5 | -------------------------------------------------------------------------------- /consul_config/attributes/sidekiq.rb: -------------------------------------------------------------------------------- 1 | default[:consul][:config] = "https://raw.githubusercontent.com/wanelo/nagios-checks/master/check_sidekiq_queue" 2 | -------------------------------------------------------------------------------- /librato-collectd/recipes/_service.rb: -------------------------------------------------------------------------------- 1 | service "collectd" do 2 | supports :status => true, :restart => true, :reload => true 3 | action [ :enable, :start ] 4 | end 5 | -------------------------------------------------------------------------------- /consul_config/recipes/nginx.rb: -------------------------------------------------------------------------------- 1 | consul_check_def "nginx" do 2 | http "http://localhost/nginx_status" 3 | interval "30s" 4 | 5 | notifies :reload, "service[consul]" 6 | end 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Polydice's Cookbooks Collection 2 | ========= 3 | 4 | Polydice's cookbooks collection for AWS OpsWorks. 5 | 6 | Most of cookbooks are drawn from other open source projects. Please check the listing below for attributions. 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | coverage 6 | InstalledFiles 7 | lib/bundler/man 8 | pkg 9 | rdoc 10 | spec/reports 11 | test/tmp 12 | test/version_tmp 13 | tmp 14 | 15 | # YARD artifacts 16 | .yardoc 17 | _yardoc 18 | doc/ 19 | -------------------------------------------------------------------------------- /consul_config/recipes/rails.rb: -------------------------------------------------------------------------------- 1 | consul_service_def node[:opsworks][:applications][0][:slug_name] do 2 | tags ["rails"] 3 | check( 4 | http: "http://127.0.0.1/rack_health", 5 | interval: "30s" 6 | ) 7 | notifies :reload, "service[consul]" 8 | end 9 | -------------------------------------------------------------------------------- /consul_config/metadata.rb: -------------------------------------------------------------------------------- 1 | name "consul_config" 2 | maintainer "Richard Lee" 3 | maintainer_email "richard@polydice.com" 4 | license "Apache 2.0" 5 | description "Configures consul." 6 | version "0.1.0" 7 | 8 | depends "consul" 9 | -------------------------------------------------------------------------------- /fluentd_config/metadata.rb: -------------------------------------------------------------------------------- 1 | name "fluentd" 2 | maintainer "Richard Lee" 3 | maintainer_email "richard@polydice.com" 4 | license "Apache 2.0" 5 | description "Configures Fluentd." 6 | version "0.1.0" 7 | 8 | depends "td-agent" 9 | -------------------------------------------------------------------------------- /consul_config/recipes/fluentd_aggregator.rb: -------------------------------------------------------------------------------- 1 | consul_service_def "fluentd-aggregator" do 2 | port 24224 3 | tags ["fluentd"] 4 | check( 5 | http: "http://localhost:24220/api/plugins.json", 6 | interval: "30s" 7 | ) 8 | notifies :reload, "service[consul]" 9 | end 10 | -------------------------------------------------------------------------------- /librato-collectd/metadata.rb: -------------------------------------------------------------------------------- 1 | name "librato-collectd" 2 | maintainer "Richard Lee" 3 | maintainer_email "richard@polydice.com" 4 | license "Apache 2.0" 5 | description "install Librato's Collectd" 6 | version "0.1.0" 7 | 8 | depends "packagecloud" 9 | -------------------------------------------------------------------------------- /fluentd_config/recipes/chgrp.rb: -------------------------------------------------------------------------------- 1 | service "td-agent" do 2 | action [:enable, :restart] 3 | end 4 | 5 | group "www-data" do 6 | action :modify 7 | members "td-agent" 8 | append true 9 | end 10 | 11 | group "adm" do 12 | action :modify 13 | members "td-agent" 14 | append true 15 | end 16 | -------------------------------------------------------------------------------- /elasticsearch_config/metadata.rb: -------------------------------------------------------------------------------- 1 | name "elasticsearch_config" 2 | maintainer "Frozenfung" 3 | maintainer_email "fung@polydice.com" 4 | license "Apache 2.0" 5 | description "Configures Elasticsearch" 6 | version "0.1.0" 7 | 8 | depends "monit" 9 | depends "java" 10 | depends "elasticsearch" 11 | 12 | -------------------------------------------------------------------------------- /consul_config/recipes/wordpress.rb: -------------------------------------------------------------------------------- 1 | consul_check_def "hhvm" do 2 | http "http://localhost:9000/check-health" 3 | interval "30s" 4 | end 5 | 6 | consul_service_def "blog-wordpress" do 7 | port 80 8 | tags ["http"] 9 | check( 10 | interval: "30s", 11 | http: "http://localhost/wp-admin/" 12 | ) 13 | notifies :reload, "service[consul]" 14 | end 15 | -------------------------------------------------------------------------------- /consul_config/recipes/sidekiq.rb: -------------------------------------------------------------------------------- 1 | remote_file "/usr/local/bin/check_sidekiq" do 2 | source node[:consul][:config] 3 | owner "root" 4 | group "root" 5 | mode "0755" 6 | action :create 7 | end 8 | 9 | host = node[:deploy][:icook][:env][:REDIS_URL].sub(/\w+\:\/\//, "").sub(/\/1/, "") 10 | 11 | consul_check_def "sidekiq" do 12 | script "/usr/local/bin/check_sidekiq -h #{host} -d 1" 13 | interval "30s" 14 | end 15 | -------------------------------------------------------------------------------- /librato-collectd/recipes/docker.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: librato-collectd 3 | # Recipe:: docker 4 | # 5 | # Copyright 2015, Richard Lee 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | 10 | group "docker" do 11 | action :modify 12 | members "nobody" 13 | append true 14 | end 15 | 16 | service "collectd" do 17 | supports :status => true, :restart => true, :reload => true 18 | action [:restart] 19 | end 20 | 21 | include_recipe 'librato-collectd::_service' 22 | -------------------------------------------------------------------------------- /consul_config/recipes/elasticsearch.rb: -------------------------------------------------------------------------------- 1 | remote_file "/usr/local/bin/check_elasticsearch" do 2 | source "https://raw.githubusercontent.com/orthecreedence/check_elasticsearch/master/check_elasticsearch" 3 | owner "root" 4 | group "root" 5 | mode "0755" 6 | action :create 7 | end 8 | 9 | consul_service_def "elasticsearch" do 10 | port 9200 11 | tags ["elasticsearch"] 12 | check( 13 | script: "/usr/local/bin/check_elasticsearch", 14 | interval: "30s" 15 | ) 16 | notifies :reload, "service[consul]" 17 | end 18 | -------------------------------------------------------------------------------- /opsworks_ecs/templates/default/ecs.config.erb: -------------------------------------------------------------------------------- 1 | ECS_LOGFILE=/log/ecs-agent.log 2 | ECS_LOGLEVEL=<%= node["opsworks_ecs"]["ecs-agent"]["loglevel"] %> 3 | ECS_DATADIR=/data 4 | ECS_CLUSTER=<%= node["opsworks_ecs"]["ecs_cluster_name"] %> 5 | <% if node["opsworks_ecs"]["auth"]["type"] -%> 6 | ECS_ENGINE_AUTH_TYPE=<%= node["opsworks_ecs"]["auth"]["type"] %> 7 | <% end -%> 8 | <% if node["opsworks_ecs"]["auth"]["data"] -%> 9 | ECS_ENGINE_AUTH_DATA=<%= node["opsworks_ecs"]["auth"]["data"] %> 10 | <% end -%> 11 | <% if node["opsworks_ecs"]["logging_drivers"] -%> 12 | ECS_AVAILABLE_LOGGING_DRIVERS=<%= node["opsworks_ecs"]["logging_drivers"].to_json %> 13 | <% end -%> 14 | -------------------------------------------------------------------------------- /elasticsearch_config/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: elasticsearch 3 | # Recipe:: default 4 | # 5 | # Copyright 2015, Frozenfung 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | 10 | include_recipe "monit" 11 | include_recipe "java" 12 | include_recipe "elasticsearch" 13 | include_recipe "elasticsearch::monit" 14 | include_recipe "elasticsearch::plugins" 15 | include_recipe "elasticsearch::aws" 16 | 17 | if url = node[:elasticsearch][:corpus][:ik] 18 | script "install_ik_data" do 19 | interpreter "bash" 20 | user "root" 21 | cwd node[:elasticsearch][:default_path] 22 | code <<-EOH 23 | rm ik.tar.gz* 24 | wget #{url} 25 | tar -zxf ik.tar.gz 26 | EOH 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /fluentd_config/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: fluentd_config 3 | # Recipe:: default 4 | # 5 | # Copyright 2015, Richard Lee 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | 10 | include_recipe "td-agent::default" 11 | 12 | url = if node[:fluentd][:config_url].is_a?(String) 13 | node[:fluentd][:config_url] 14 | else 15 | node[:fluentd][:config_url][node[:opsworks][:instance][:layers][0]] 16 | end 17 | 18 | if url 19 | service "td-agent" do 20 | action [ :enable, :start ] 21 | end 22 | 23 | remote_file "/etc/td-agent/td-agent.conf" do 24 | source url 25 | owner "root" 26 | group "root" 27 | mode 00644 28 | notifies :restart, "service[td-agent]" 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source "https://supermarket.getchef.com" 2 | 3 | cookbook 'ark' 4 | cookbook 'build-essential' 5 | cookbook 'consul' 6 | cookbook 'datadog' 7 | cookbook 'elasticsearch', '< 1' 8 | cookbook 'ipaddr_extensions' 9 | cookbook 'java', github: 'agileorbit-cookbooks/java' 10 | cookbook 'jenkins' 11 | cookbook 'mosh' 12 | cookbook 'rsyslog' 13 | cookbook 'sysctl' 14 | cookbook 'td-agent', github: 'treasure-data/chef-td-agent' 15 | cookbook 'ulimit' 16 | cookbook 'opsworks_wordpress', github: 'polydice/opsworks_wordpress' 17 | cookbook 'opsworks-layer-json-attributes', github: 'jcoleman/opsworks-layer-json-attributes-cookbook' 18 | cookbook 'monit' 19 | 20 | # Before Chef 12 21 | cookbook 'firewall', '< 2' 22 | cookbook 'poise', '< 2' 23 | cookbook 'libarchive', '< 0.5' 24 | -------------------------------------------------------------------------------- /librato-collectd/recipes/default.rb: -------------------------------------------------------------------------------- 1 | packagecloud_repo "librato/librato-collectd" do 2 | type "deb" 3 | end 4 | 5 | ruby_block 'librato-credentials' do 6 | block do 7 | f = Chef::Util::FileEdit.new('/opt/collectd/etc/collectd.conf.d/librato.conf') 8 | f.search_file_replace(%r{User ""}, 9 | "User \"#{node[:librato][:collectd][:user]}\"") 10 | f.search_file_replace(%r{Password ""}, 11 | "Password \"#{node[:librato][:collectd][:password]}\"") 12 | f.write_file 13 | end 14 | 15 | notifies :restart, "service[collectd]" 16 | action :nothing 17 | end 18 | 19 | package "collectd" do 20 | notifies :run, "ruby_block[librato-credentials]" 21 | end 22 | 23 | include_recipe 'librato-collectd::_service' 24 | -------------------------------------------------------------------------------- /opsworks_ecs/recipes/setup_ubuntu.rb: -------------------------------------------------------------------------------- 1 | file "/etc/apt/sources.list.d/docker.list" do 2 | content "deb #{node["opsworks_ecs"]["ubuntu_docker_repository"]["url"]} #{node["lsb"]["id"].downcase}-#{node["lsb"]["codename"]} #{node["opsworks_ecs"]["ubuntu_docker_repository"]["component"]}" 3 | end 4 | 5 | execute "Import docker repository key" do 6 | command "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys #{node["opsworks_ecs"]["ubuntu_docker_repository"]["fingerprint"]}" 7 | retries 5 8 | 9 | not_if do 10 | OpsWorks::ShellOut.shellout("apt-key adv --list-public-keys #{node["opsworks_ecs"]["ubuntu_docker_repository"]["fingerprint"]}") rescue false 11 | end 12 | end 13 | 14 | execute "apt-get update" 15 | 16 | package "linux-image-extra-#{`uname -r`.strip}" 17 | 18 | package "docker-engine" do 19 | options "--no-install-recommends" 20 | end 21 | -------------------------------------------------------------------------------- /elasticsearch_config/test/integration/default/serverspec/default_spec.rb: -------------------------------------------------------------------------------- 1 | require "serverspec" 2 | 3 | set :os, :family => "ubuntu" 4 | set :backend, :exec 5 | 6 | # Verifying Java is installed in correct version 7 | describe command('java -version') do 8 | its(:stdout) { should match /java version \"1.8/ } 9 | its(:exit_status) { should eq 0 } 10 | end 11 | 12 | describe service("monit") do 13 | it { should be_enabled } 14 | it { should be_running } 15 | end 16 | 17 | describe service('elasticsearch') do 18 | it { should be_enabled } 19 | it { should be_running } 20 | end 21 | 22 | describe service('elasticsearch') do 23 | it { should be_monitored_by('monit') } 24 | end 25 | 26 | # Verifying ES plugins are installed 27 | describe command('plugin -l') do 28 | its(:stdout) { should match /analysis-ik/ } 29 | its(:stdout) { should match /cloud-aws/ } 30 | its(:exit_status) { should eq 0 } 31 | end 32 | 33 | # Verifying ik config exists 34 | describe file('/usr/local/etc/elasticsearch/ik.tar.gz') do 35 | it { should be_file } 36 | end 37 | 38 | describe file('/usr/local/etc/elasticsearch/ik') do 39 | it { should be_directory } 40 | end 41 | -------------------------------------------------------------------------------- /Berksfile.lock: -------------------------------------------------------------------------------- 1 | DEPENDENCIES 2 | ark 3 | build-essential 4 | consul 5 | datadog 6 | elasticsearch (< 1.0.0) 7 | firewall (< 2.0.0) 8 | ipaddr_extensions 9 | java 10 | git: git://github.com/agileorbit-cookbooks/java.git 11 | revision: 00b9c8c04e3684adcb7ae802cdea1bd9ae28c317 12 | jenkins 13 | libarchive (< 0.5.0) 14 | monit 15 | mosh 16 | opsworks-layer-json-attributes 17 | git: git://github.com/jcoleman/opsworks-layer-json-attributes-cookbook.git 18 | revision: 09bf7adc1e931e05241893737e4efdee1b85e893 19 | opsworks_wordpress 20 | git: git://github.com/polydice/opsworks_wordpress.git 21 | revision: d9ebfa25640d0e637d2ae668dc8bcacf09a80e9f 22 | poise (< 2.0.0) 23 | rsyslog 24 | sysctl 25 | td-agent 26 | git: git://github.com/treasure-data/chef-td-agent.git 27 | revision: f4ae0f7ce48e1cd59d75d8226bfa79e6c7307590 28 | ulimit 29 | 30 | GRAPH 31 | 7-zip (1.0.2) 32 | windows (>= 1.2.2) 33 | apt (2.9.2) 34 | ark (0.9.0) 35 | 7-zip (>= 0.0.0) 36 | windows (>= 0.0.0) 37 | build-essential (2.2.4) 38 | chef-provisioning (0.1.2) 39 | build-essential (>= 0.0.0) 40 | chef-sugar (3.1.1) 41 | chef_handler (1.2.0) 42 | compat_resource (12.5.14) 43 | consul (0.10.1) 44 | chef-provisioning (>= 0.0.0) 45 | golang (~> 1.4) 46 | libarchive (~> 0.4.0) 47 | packagecloud (>= 0.0.0) 48 | runit (>= 0.0.0) 49 | yum-repoforge (>= 0.0.0) 50 | datadog (0.1.2) 51 | apt (>= 0.0.0) 52 | chef_handler (>= 1.0.6) 53 | yum (>= 0.0.0) 54 | elasticsearch (0.3.14) 55 | ark (>= 0.2.4) 56 | firewall (1.6.2) 57 | poise (~> 1.0) 58 | golang (1.7.0) 59 | hhvm (0.6.0) 60 | apt (>= 0.0.0) 61 | yum (>= 0.0.0) 62 | ipaddr_extensions (0.3.1) 63 | java (1.37.0) 64 | apt (>= 0.0.0) 65 | jenkins (2.4.1) 66 | apt (~> 2.0) 67 | runit (~> 1.5) 68 | yum (~> 3.0) 69 | libarchive (0.4.4) 70 | apt (~> 2.5) 71 | build-essential (~> 2.0) 72 | monit (0.7.5) 73 | mosh (0.4.0) 74 | apt (>= 0.0.0) 75 | yum (>= 0.0.0) 76 | yum-epel (>= 0.0.0) 77 | ohai (2.0.4) 78 | openssl (4.4.0) 79 | chef-sugar (>= 3.1.1) 80 | opsworks-layer-json-attributes (0.1.0) 81 | opsworks_wordpress (0.1.0) 82 | hhvm (>= 0.0.0) 83 | openssl (>= 0.0.0) 84 | packagecloud (0.2.0) 85 | poise (1.0.12) 86 | rsyslog (3.0.0) 87 | compat_resource (>= 0.0.0) 88 | runit (1.7.6) 89 | packagecloud (>= 0.0.0) 90 | sysctl (0.6.2) 91 | ohai (>= 0.0.0) 92 | td-agent (2.1.5) 93 | apt (>= 0.0.0) 94 | yum (>= 0.0.0) 95 | ulimit (0.3.3) 96 | windows (1.38.4) 97 | chef_handler (>= 0.0.0) 98 | yum (3.8.2) 99 | yum-epel (0.6.5) 100 | yum (~> 3.2) 101 | yum-repoforge (0.5.7) 102 | yum (~> 3.2) 103 | yum-epel (>= 0.0.0) 104 | --------------------------------------------------------------------------------