Skip to content

Commit

Permalink
add a bunch of cleaned up cookbooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jsierles committed Jul 7, 2011
1 parent 4747dd4 commit a6ddaa9
Show file tree
Hide file tree
Showing 27 changed files with 490 additions and 3 deletions.
6 changes: 6 additions & 0 deletions 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"
21 changes: 21 additions & 0 deletions 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
22 changes: 22 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions 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"
27 changes: 27 additions & 0 deletions 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
35 changes: 35 additions & 0 deletions 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
9 changes: 9 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions logrotate/metadata.rb
@@ -0,0 +1,4 @@
maintainer "Joshua Sierles"
maintainer_email "joshua@diluvia.net"
description "Configures logrotate"
version "0.2"
1 change: 1 addition & 0 deletions logrotate/recipes/default.rb
@@ -0,0 +1 @@
package "logrotate"
23 changes: 23 additions & 0 deletions 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
}
2 changes: 2 additions & 0 deletions rails/attributes/delayed_job.rb
@@ -0,0 +1,2 @@
rails Mash.new unless attribute?("rails")

6 changes: 6 additions & 0 deletions 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
35 changes: 35 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions rails/files/default/git_ssh_wrapper
@@ -0,0 +1,2 @@
#!/bin/bash
exec ssh -oStrictHostKeyChecking=no -i /local/app/.ssh/id_rsa $@
10 changes: 10 additions & 0 deletions 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"
54 changes: 54 additions & 0 deletions 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
45 changes: 45 additions & 0 deletions 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

0 comments on commit a6ddaa9

Please sign in to comment.