unicorn.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #
  2. # Cookbook Name:: application
  3. # Recipe:: unicorn
  4. #
  5. # Copyright 2009, Opscode, Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. Chef::Log.warn "The application::unicorn recipe is deprecated and will go away on Aug 1st. See the README for migration information."
  20. app = node.run_state[:current_app]
  21. include_recipe "unicorn"
  22. node.default[:unicorn][:worker_timeout] = 60
  23. node.default[:unicorn][:preload_app] = false
  24. node.default[:unicorn][:worker_processes] = [node[:cpu][:total].to_i * 4, 8].min
  25. node.default[:unicorn][:preload_app] = false
  26. node.default[:unicorn][:before_fork] = 'sleep 1'
  27. node.default[:unicorn][:port] = '8080'
  28. node.set[:unicorn][:options] = { :tcp_nodelay => true, :backlog => 100 }
  29. unicorn_config "/etc/unicorn/#{app['id']}.rb" do
  30. listen({ node[:unicorn][:port] => node[:unicorn][:options] })
  31. working_directory ::File.join(app['deploy_to'], 'current')
  32. worker_timeout node[:unicorn][:worker_timeout]
  33. preload_app node[:unicorn][:preload_app]
  34. worker_processes node[:unicorn][:worker_processes]
  35. before_fork node[:unicorn][:before_fork]
  36. end
  37. runit_service app['id'] do
  38. template_name 'unicorn'
  39. cookbook 'application'
  40. options(
  41. :app => app,
  42. :rails_env => node.run_state[:rails_env] || node.chef_environment,
  43. :smells_like_rack => ::File.exists?(::File.join(app['deploy_to'], "current", "config.ru"))
  44. )
  45. run_restart false
  46. end
  47. if ::File.exists?(::File.join(app['deploy_to'], "current"))
  48. d = resources(:deploy_revision => app['id'])
  49. d.restart_command do
  50. execute "/etc/init.d/#{app['id']} hup"
  51. end
  52. end