Skip to content
Browse files

add a bunch of cleaned up cookbooks

  • Loading branch information...
1 parent 4747dd4 commit a6ddaa9eac0c57abd899243d77e1bd30eab85101 @jsierles committed
View
6 bluepill/attributes/bluepill.rb
@@ -0,0 +1,6 @@
+default.bluepill[:bin] = languages[:ruby][:bin_dir] + "/bluepill"
+default.bluepill[:config_dir] = "/etc/bluepill"
+default.bluepill[:log_dir] = "/var/log/bluepill"
+default.bluepill[:pid_dir] = "/var/run/bluepill"
+
+bluepill[:version] = "0.0.51"
View
21 bluepill/definitions/bluepill_monitor.rb
@@ -0,0 +1,21 @@
+define :bluepill_monitor, :enable => true, :rack_config_path => false do
+ include_recipe "bluepill"
+ config_path = "#{node[:bluepill][:config_dir]}/#{params[:name]}.conf.rb"
+
+ execute "load-bluepill-#{params[:name]}" do
+ command "bluepill load #{node[:bluepill][:config_dir]}/#{params[:name]}.conf.rb"
+ action :nothing
+ end
+
+ execute "restart-bluepill-#{params[:name]}" do
+ command "bluepill restart #{params[:name]}"
+ action :nothing
+ end
+
+ template config_path do
+ source params[:source] || "bluepill_#{params[:name]}.conf.erb"
+ cookbook params[:cookbook]
+ variables params[:variables] || params
+ notifies :run, resources("execute[load-bluepill-#{params[:name]}]")
+ end
+end
View
22 bluepill/definitions/bluepill_service.rb
@@ -0,0 +1,22 @@
+define :bluepill_service, :enable => true, :rack_config_path => false do
+ include_recipe "bluepill"
+ config_path = "#{node[:bluepill][:config_dir]}/#{params[:name]}.conf.rb"
+
+ service params[:name]
+
+ link "/etc/init.d/#{params[:name]}" do
+ to node[:bluepill][:bin]
+ end
+
+ service params[:name] do
+ supports :restart => true, :status => true, :load => true
+ action :nothing
+ end
+
+ template config_path do
+ source params[:source] || "bluepill_#{params[:name]}.conf.erb"
+ cookbook params[:cookbook]
+ variables params
+ notifies :load, resources(:service => params[:name])
+ end
+end
View
4 bluepill/metadata.rb
@@ -0,0 +1,4 @@
+maintainer "Joshua Sierles"
+maintainer_email "joshua@diluvia.net"
+description "Installs bluepill and provides definitions and templates for monitoring"
+version "0.8"
View
27 bluepill/recipes/default.rb
@@ -0,0 +1,27 @@
+gem_package "bluepill" do
+ version node[:bluepill][:version]
+end
+
+directory node[:bluepill][:config_dir] do
+ owner "root"
+ group "root"
+end
+
+directory node[:bluepill][:log_dir] do
+ owner "root"
+ group "root"
+end
+
+directory node[:bluepill][:pid_dir] do
+ owner "root"
+ group "root"
+end
+
+template "/etc/init.d/bluepill" do
+ source "init.sh.erb"
+ mode 0755
+end
+
+service "bluepill" do
+ action [:enable, :start]
+end
View
35 bluepill/templates/default/init.sh.erb
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides: bluepill
+# Required-Start:
+# Required-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 1
+# Short-Description: Bluepill initializer
+### END INIT INFO
+
+. /lib/lsb/init-functions
+
+case "$1" in
+ start)
+ log_daemon_msg "Starting bluepill services"
+ for i in <%= @node[:bluepill][:config_dir] %>/*conf.rb; do
+ <%= @node[:languages][:ruby][:bin_dir] %>/bluepill load $i
+ done
+ log_end_msg 0
+ ;;
+ stop)
+ echo "Stop is not implemented, since bluepill processes are run independently."
+ ;;
+ restart)
+ for i in <%= @node[:bluepill][:config_dir] %>/*conf.rb; do
+ <%= @node[:languages][:ruby][:bin_dir] %>/bluepill load $i
+ done
+ ;;
+ *)
+ log_action_msg "Usage: /etc/init.d/bluepill start"
+ exit
+esac
+
+exit 0
View
9 logrotate/definitions/logrotate.rb
@@ -0,0 +1,9 @@
+define :logrotate, :frequency => "daily", :rotate_count => 5, :rotate_if_empty => false, :missing_ok => true, :compress => true, :enable => true do
+ template "/etc/logrotate.d/#{params[:name]}" do
+ action :delete unless params[:enable]
+ cookbook "logrotate"
+ source "logrotate.conf.erb"
+ variables(:p => params)
+ backup 0
+ end
+end
View
4 logrotate/metadata.rb
@@ -0,0 +1,4 @@
+maintainer "Joshua Sierles"
+maintainer_email "joshua@diluvia.net"
+description "Configures logrotate"
+version "0.2"
View
1 logrotate/recipes/default.rb
@@ -0,0 +1 @@
+package "logrotate"
View
23 logrotate/templates/default/logrotate.conf.erb
@@ -0,0 +1,23 @@
+<%= @p[:files].to_a.join("\n") %> {
+ <% if @p[:size_limit] %>
+ size <%= @p[:size_limit] %>
+ <% else %>
+ <%= @p[:frequency] %>
+ <% end %>
+ rotate <%= @p[:rotate_count] %>
+ <% if @p[:compress] %>
+ dateext
+ compress
+ <% end %>
+ <% if @p[:missing_ok] %>
+ missingok
+ <% end %>
+ <% %>
+ <% if !@p[:rotate_if_empty] %>
+ notifempty
+ <% end %>
+ sharedscripts
+ postrotate
+ <%= @p[:restart_command] %>
+ endscript
+}
View
2 rails/attributes/delayed_job.rb
@@ -0,0 +1,2 @@
+rails Mash.new unless attribute?("rails")
+
View
6 rails/attributes/rails.rb
@@ -0,0 +1,6 @@
+default[:rails][:asset_environment] = "production"
+default[:rails][:worker_count] = 8
+default[:rails][:app_server] = "unicorn"
+default[:rails][:memory_limit] = '400' # megabytes
+default[:rails][:monitor_interval] = '30' # seconds
+default[:rails][:cpu_limit] = '50' # percent
View
35 rails/files/default/copy.rb
@@ -0,0 +1,35 @@
+require 'fileutils'
+
+verbose = false
+
+from = ARGV.shift or abort "need source directory"
+to = ARGV.shift or abort "need target directory"
+
+exclude = ARGV
+
+from = File.expand_path(from)
+to = File.expand_path(to)
+
+Dir.chdir(from) do
+ FileUtils.mkdir_p(to)
+ queue = Dir.glob("*", File::FNM_DOTMATCH)
+ while queue.any?
+ item = queue.shift
+ name = File.basename(item)
+
+ next if name == "." || name == ".."
+ next if exclude.any? { |pattern| File.fnmatch(pattern, item) }
+
+ source = File.join(from, item)
+ target = File.join(to, item)
+
+ if File.symlink?(item)
+ FileUtils.ln_s(File.readlink(source), target)
+ elsif File.directory?(item)
+ queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH)
+ FileUtils.mkdir_p(target, :mode => File.stat(item).mode)
+ else
+ FileUtils.ln(source, target)
+ end
+ end
+end
View
2 rails/files/default/git_ssh_wrapper
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec ssh -oStrictHostKeyChecking=no -i /local/app/.ssh/id_rsa $@
View
10 rails/metadata.rb
@@ -0,0 +1,10 @@
+maintainer "Joshua Sierles"
+maintainer_email "joshua@diluvia.net"
+description "Configures rails apps"
+version "0.2"
+depends "users"
+depends "unicorn"
+depends "logrotate"
+depends "bluepill"
+depends "ssl_certificates"
+depends "bundler"
View
54 rails/recipes/app_dependencies.rb
@@ -0,0 +1,54 @@
+if node[:active_applications]
+
+ directory "/u/apps" do
+ owner "app"
+ group "app"
+ mode 0755
+ end
+
+ node[:active_applications].each do |name, conf|
+
+ app = search(:apps, "id:#{conf[:app_name] || name}").first
+ app_name = name
+ app_root = "/u/apps/#{app_name}"
+
+ %w(config tmp sockets log pids system bin).each do |dir|
+ directory "/u/apps/#{app_name}/shared/#{dir}" do
+ recursive true
+ owner "app"
+ group "app"
+ end
+ end
+
+ if app
+
+ if app[:packages]
+ app[:packages].each do |package_name|
+ package package_name
+ end
+ end
+
+ if app[:gems]
+ app[:gems].each do |g|
+ if g.is_a? Array
+ gem_package g.first do
+ version g.last
+ end
+ else
+ gem_package g
+ end
+ end
+ end
+
+ if app[:symlinks]
+ app[:symlinks].each do |target, source|
+ link target do
+ to source
+ end
+ end
+ end
+ end
+ end
+else
+ Chef::Log.info "Add an :active_applications attribute to configure this node's Rails apps"
+end
View
45 rails/recipes/apps.rb
@@ -0,0 +1,45 @@
+require_recipe "nginx"
+require_recipe "rails::app_dependencies"
+require_recipe "unicorn"
+require_recipe "bluepill"
+require_recipe "users"
+
+node[:active_applications].each do |name, conf|
+
+ app = search(:apps, "id:#{conf[:app_name] || name}").first
+
+ app_name = name
+ app_root = "/u/apps/#{name}"
+
+ full_name = "#{app_name}_#{conf[:env]}"
+ filename = "#{filename}_#{conf[:env]}.conf"
+
+ template "/etc/nginx/sites-available/#{full_name}" do
+ source "app_nginx.conf.erb"
+ variables :full_name => full_name, :app => app, :conf => conf, :app_name => app_name
+ notifies :reload, resources(:service => "nginx")
+ end
+
+ bluepill_monitor full_name do
+ source "bluepill_unicorn.conf.erb"
+ app_root "#{app_root}/current"
+ preload app[:preload] || true
+ env conf[:env]
+ interval node[:rails][:monitor_interval]
+ user "app"
+ group "app"
+ memory_limit app[:memory_limit] || node[:rails][:memory_limit]
+ cpu_limit app[:cpu_limit] || node[:rails][:cpu_limit]
+ end
+
+ nginx_site full_name
+
+ logrotate full_name do
+ files "/u/apps/#{app_name}/current/log/*.log"
+ frequency "daily"
+ rotate_count 14
+ compress true
+ restart_command "/etc/init.d/nginx reload > /dev/null"
+ end
+
+end
View
74 rails/templates/default/app_nginx.conf.erb
@@ -0,0 +1,74 @@
+upstream <%= @full_name %> {
+ server unix:/u/apps/<%= @app_name %>/shared/sockets/unicorn.sock fail_timeout=0;
+}
+
+server {
+ listen <%= @node[:rails][:nginx_port] %>;
+ server_name <%= @app[:environments][@conf[:env]][:domains].join(" ") %>;
+ server_name_in_redirect off;
+
+ <% if @app[:rewrites] %>
+ <% @app[:rewrites].each do |path, args| %>
+ <% if args[:condition] -%>if (<%= args[:condition] %>) {<% end -%>
+ rewrite <%= path %> <%= args[:replacement] %> <%= args[:flag] %>;
+ <% if args[:condition] -%>}<% end -%>
+ <% end %>
+ <% end %>
+
+ root /u/apps/<%= @app_name %>/current/public;
+
+ access_log /u/apps/<%= @app_name %>/shared/log/access.log main;
+ error_log /u/apps/<%= @app_name %>/shared/log/error.log;
+
+ include /etc/nginx/helpers/expires.conf;
+ include /etc/nginx/helpers/maintenance.conf;
+ include /etc/nginx/helpers/invalid_requests.conf;
+ include /etc/nginx/helpers/headers.conf;
+
+ location /nginx_status {
+ stub_status on;
+ access_log off;
+ allow 127.0.0.1/32;
+ deny all;
+ }
+
+ location /_raindrops {
+ access_log off;
+ <% node[:networks].each do |name, addresses| %>
+ allow <%= addresses[:network] %>/<%= IPAddr.new(addresses[:netmask]).to_i.to_s(2).count("1") %>;
+ <% end %>
+ allow 127.0.0.1/32;
+ deny all;
+ proxy_pass http://<%= @full_name %>;
+ }
+
+ location / {
+
+ # use for cloudfront asset cache busting
+ # rewrite ^/rev_(.+?)/(.*)$ /$2 last;
+
+ proxy_buffer_size 16k;
+ proxy_buffers 8 16k;
+ proxy_busy_buffers_size 32k;
+
+ if (-f $request_filename) {
+ break;
+ }
+
+ if (!-f $request_filename) {
+ proxy_pass http://<%= @full_name %>;
+ break;
+ }
+ }
+
+ error_page 500 502 503 504 /500.html;
+ error_page 404 /404.html;
+
+ location = /500.html {
+ root /u/apps/<%= @app_name %>/current/public;
+ }
+
+ location = /400.html {
+ root /u/apps/<%= @app_name %>/current/public;
+ }
+}
View
30 rails/templates/default/bluepill_unicorn.conf.erb
@@ -0,0 +1,30 @@
+ENV['PATH'] = "#{ENV['PATH']}:/usr/local/bin"
+
+Bluepill.application("<%= @name %>") do |app|
+ app.working_dir = "<%= @app_root %>"
+ <% if @environment_vars %>
+ app.environment = {<% @environment_vars.each do |k, v| %><%= "\"#{k}\" => \"#{v}\"" %><% end %>}
+ <% end %>
+ app.process("<%= @name %>") do |process|
+ process.start_command = "/usr/bin/env RAILS_ENV=<%= @env %> /usr/local/bin/bundle exec unicorn <%= @app_root %>/config.ru -Dc <%= @app_root %>/config/unicorn.conf.rb -E <%= @env %>"
+ process.stop_command = "kill -QUIT {{PID}}"
+ process.restart_command = "kill -<%= @preload ? 'USR2' : 'HUP' %> {{PID}}"
+ process.stdout = process.stderr = "<%= @app_root %>/log/unicorn.log"
+ process.pid_file = "<%= @app_root %>/tmp/pids/unicorn.pid"
+ process.checks :mem_usage, :every => 10.seconds, :below => <%= @memory_limit %>.megabytes, :times => [3, 5]
+ process.uid = "<%= @user %>"
+ process.gid = "<%= @group %>"
+
+ process.start_grace_time = 10.seconds
+ process.start_grace_time = 10.seconds
+ process.restart_grace_time = 10.seconds
+
+ process.checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
+
+ process.monitor_children do |cp|
+ cp.checks :mem_usage, :every => 10, :below => <%= @memory_limit %>.megabytes, :times => [3, 5]
+ process.checks :cpu_usage, :every => 10.seconds, :below => <%= @cpu_limit %>, :times => 5
+ cp.stop_command = "kill -QUIT {{PID}}"
+ end
+ end
+end
View
6 ruby_enterprise_edition/metadata.rb
@@ -1,5 +1,5 @@
-maintainer "37signals"
-maintainer_email "sysadmins@37signals.com"
+maintainer "Joshua Sierles"
+maintainer_email "joshua@diluvia.net"
description "Configures REE"
-version "0.1"
+version "0.2"
depends "ruby"
View
1 timezone/attributes/timezone.rb
@@ -0,0 +1 @@
+default.timezone = "UTC"
View
4 timezone/metadata.rb
@@ -0,0 +1,4 @@
+maintainer "Joshua Sierles"
+maintainer_email "joshua@diluvia.net"
+description "Configures timezone"
+version "0.2"
View
5 timezone/recipes/default.rb
@@ -0,0 +1,5 @@
+link "/etc/localtime" do
+ filename = "/usr/share/zoneinfo/#{node[:timezone]}"
+ to filename
+ only_if { File.exists? filename }
+end
View
3 unicorn/attributes/unicorn.rb
@@ -0,0 +1,3 @@
+default.unicorn[:worker_count] = 6
+default.unicorn[:timeout] = 10
+default.unicorn[:version] = "4.0.1"
View
50 unicorn/files/default/unicornctl
@@ -0,0 +1,50 @@
+#!/usr/local/bin/ruby
+#
+# Control a unicorn master process
+# See http://unicorn.bogomips.org/SIGNALS.html for an explanation of each signal
+#
+
+SIGNALS_MAP = {"restart" => "USR2", "force_shutdown" => "TERM", "graceful_shutdown" => "QUIT",
+ "reopen_logs" => "USR1", "restart_workers" => "HUP", "stop_workers" => "WINCH", "add_worker" => "TTIN", "remove_worker" => "TTOU"}
+
+def usage
+ puts "unicornctl <command> [pid_path]"
+ puts "Provide one of the following commands:"
+ puts SIGNALS_MAP.keys.join(", ")
+ puts
+ puts "Pid path default relative to the current directory: tmp/pids/unicorn.pid"
+ exit
+end
+
+usage unless ARGV[0] && SIGNALS_MAP.keys.include?(ARGV[0])
+
+pid_path = ARGV[1] || Dir.pwd + "/tmp/pids/unicorn.pid"
+
+if File.exists?(pid_path)
+ old_pid = File.read(pid_path).strip
+ command = ARGV[0].downcase
+
+ puts "Restarting pid #{old_pid}..."
+ Process.kill(SIGNALS_MAP[command], File.read(pid_path).to_i)
+
+ tries = 0
+ begin
+ sleep 2
+ new_pid = File.read(pid_path).strip
+ rescue => e
+ tries += 1
+ retry unless tries >= 3
+ puts "WARNING: Restart failed. Error: #{e.message}."
+ end
+ if new_pid == old_pid
+ if command == "restart"
+ puts "PID #{new_pid} has not changed, so the deploy may have failed. Check the unicorn log for issues."
+ else
+ puts "Since this app does not preload, the master unicorn process keeps the same PID of #{new_pid}."
+ end
+ else
+ puts "New pid is #{new_pid}."
+ end
+else
+ puts "WARNING: no pid file found at #{pid_path}"
+end
View
5 unicorn/metadata.rb
@@ -0,0 +1,5 @@
+maintainer "Joshua Sierles"
+maintainer_email "joshua@diuvia.net"
+description "Configures unicorn"
+version "0.2"
+depends "ruby"
View
9 unicorn/recipes/default.rb
@@ -0,0 +1,9 @@
+include_recipe "ruby::gc_wrapper"
+
+gem_package "unicorn" do
+ version node[:unicorn][:version]
+end
+
+cookbook_file "/usr/local/bin/unicornctl" do
+ mode 0755
+end

0 comments on commit a6ddaa9

Please sign in to comment.
Something went wrong with that request. Please try again.