Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
107 lines (92 sloc) 2.82 KB
# dep 'unicorn configured' do
# requires 'unicorn.gem', 'unicorn config exists.nginx'
# end
#
# dep 'unicorn.gem' do
# provides %w[unicorn unicorn_rails]
# end
#
# dep 'unicorn config exists.nginx' do
# def unicorn_config
# var(:app_root) / 'config/unicorn.rb'
# end
# met? { Babushka::Renderable.new(unicorn_config).from?(dependency.load_path.parent / "unicorn/unicorn.rb.erb") }
# meet do
# shell "mkdir -p #{var(:app_root)}/config"
# render_erb 'unicorn/unicorn.rb.erb', :to => unicorn_config
# end
# end
# Unicorn deps, broken into three sections:
# 1. Render the unicorn config
dep 'unicorn configured' do
requires 'unicorn.gem'#, #DONE
# 'unicorn config exists.nginx' #DONE
end
dep 'unicorn.gem' do #DONE
# installs 'unicorn' => "4.1.1"
provides "unicorn", "unicorn_rails"
end
dep 'unicorn config exists.nginx' do
def unicorn_config
var(:app_root) / 'config/unicorn.rb'
end
met? { Babushka::Renderable.new(unicorn_config).from?(dependency.load_path.parent / "unicorn/unicorn.rb.erb") }
meet do
shell "mkdir -p #{var(:app_root)}/config"
shell "mkdir -p #{var(:app_root)}/log"
render_erb 'unicorn/unicorn.rb.erb', :to => unicorn_config
end
end
# 2. Set up how unicorn starts/stops
dep 'unicorn started' do
requires 'unicorn rc script'
def unicorn_pid
var(:app_pid_dir) / 'unicorn.pid'
end
met? {
unicorn_pid.exist? && sudo("ps `cat #{unicorn_pid}`")
}
meet {
sudo "/etc/init.d/unicorn start"
30.times do
if unicorn_pid.exist? then
break
else
sleep 0.1
end
end
}
end
dep 'unicorn rc script' do
requires 'unicorn conf script', 'rcconf.managed'
met? { shell("rcconf --list").val_for('unicorn') == 'on' }
meet {
render_erb 'unicorn/unicorn.init.d.erb', :to => '/etc/init.d/unicorn', :perms => '755', :sudo => true
sudo 'update-rc.d unicorn defaults'
}
end
dep 'unicorn conf script' do
met? { "/etc/unicorn/#{var(:app_name)}.conf".p.exists? }
meet {
shell "mkdir -p /etc/unicorn", :sudo => true
render_erb 'unicorn/unicorn.conf.erb', :to => "/etc/unicorn/#{var(:app_name)}.conf", :perms => '755', :sudo => true
}
end
# 3. Watch the workers with monit (for uptime)
# dep 'unicorn workers monitored' do
# requires 'monit running'
#
# helper(:monitrc) { "/etc/monit/conf.d/unicorn_workers.#{var(:app_name)}.monitrc" }
# helper(:master_monitrc) { "/etc/monit/conf.d/unicorn_master.#{var(:app_name)}.monitrc" }
#
# met? do
# sudo("grep 'Generated by babushka' #{monitrc}") &&
# sudo("grep 'Generated by babushka' #{master_monitrc}")
# end
# meet do
# render_erb "monit/unicorn_workers.monitrc.erb", :to => monitrc, :sudo => true
# render_erb "monit/unicorn_master.monitrc.erb", :to => master_monitrc, :sudo => true
# end
#
# after { sudo "monit reload" }
# end