Skip to content

Commit

Permalink
improve unicorn/bluepill integration
Browse files Browse the repository at this point in the history
  • Loading branch information
dje committed Jun 13, 2011
1 parent baf0714 commit edbd25b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/attributes/unicorn.rb
@@ -1,3 +1,3 @@
default[:unicorn][:stand_alone] = true default[:unicorn][:bundled] = false
default[:unicorn][:timeout] = 30 default[:unicorn][:timeout] = 30
default[:unicorn][:cow_friendly] = false default[:unicorn][:cow_friendly] = false
2 changes: 1 addition & 1 deletion app/metadata.rb
Expand Up @@ -3,7 +3,7 @@
license "Apache 2.0" license "Apache 2.0"
description "Installs/Configures a Rails app" description "Installs/Configures a Rails app"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.0" version "0.1.1"


supports "ubuntu" supports "ubuntu"


Expand Down
18 changes: 17 additions & 1 deletion app/recipes/bluepill.rb
@@ -1,13 +1,29 @@
include_recipe "bluepill" include_recipe "bluepill"


if node[:unicorn][:bundled]
# Bundling unicorn with the app is the preferred method.
red_unicorn = "bundle exec red_unicorn"
else
# Otherwise attempt to find gems bin path. This smells bad to me.
require "yaml"
path = ""
env = YAML::load(`gem environment`)["RubyGems Environment"]
env.each do |e|
path = e["EXECUTABLE DIRECTORY"] if e.key?("EXECUTABLE DIRECTORY")
end
red_unicorn = "red_unicorn --unicorn-exec #{path}/unicorn"
end

template "/etc/bluepill/app.pill" do template "/etc/bluepill/app.pill" do
source "bluepill.erb" source "bluepill.erb"
variables( :environment => node[:app][:rails_env], variables( :red_unicorn => red_unicorn,
:environment => node[:app][:rails_env],
:start_grace_time => node[:bluepill][:start_grace_time], :start_grace_time => node[:bluepill][:start_grace_time],
:stop_grace_time => node[:bluepill][:stop_grace_time], :stop_grace_time => node[:bluepill][:stop_grace_time],
:restart_grace_time => node[:bluepill][:restart_grace_time], :restart_grace_time => node[:bluepill][:restart_grace_time],
:mem_usage_mb => node[:bluepill][:mem_usage_mb], :mem_usage_mb => node[:bluepill][:mem_usage_mb],
:cpu_usage_percent => node[:bluepill][:cpu_usage_percent] ) :cpu_usage_percent => node[:bluepill][:cpu_usage_percent] )
notifies :load, "bluepill_service[app]"
end end


bluepill_service "app" do bluepill_service "app" do
Expand Down
2 changes: 1 addition & 1 deletion app/recipes/unicorn.rb
@@ -1,4 +1,4 @@
gem_package "red_unicorn" if node[:unicorn][:stand_alone] gem_package "red_unicorn" unless node[:unicorn][:bundled]


directory "/etc/unicorn" directory "/etc/unicorn"


Expand Down
6 changes: 3 additions & 3 deletions app/templates/default/bluepill.erb
Expand Up @@ -3,9 +3,9 @@ Bluepill.application("app") do |app|
process.pid_file = "/var/run/unicorn/unicorn.pid" process.pid_file = "/var/run/unicorn/unicorn.pid"
process.working_dir = "/var/www/current" process.working_dir = "/var/www/current"


process.start_command = "red_unicorn --unicorn-exec /usr/local/bin/unicorn --env <%= @environment %> start" process.start_command = "<%= @red_unicorn %> --env <%= @environment %> start"
process.stop_command = "red_unicorn --unicorn-exec /usr/local/bin/unicorn stop" process.stop_command = "<%= @red_unicorn %> stop"
process.restart_command = "red_unicorn --unicorn-exec /usr/local/bin/unicorn restart" process.restart_command = "<%= @red_unicorn %> restart"


process.uid = process.gid = "www-data" process.uid = process.gid = "www-data"


Expand Down

0 comments on commit edbd25b

Please sign in to comment.