unicorn.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. app = node.run_state[:current_app]
  20. include_recipe "unicorn"
  21. node.default[:unicorn][:worker_timeout] = 60
  22. node.default[:unicorn][:preload_app] = false
  23. node.default[:unicorn][:worker_processes] = [node[:cpu][:total].to_i * 4, 8].min
  24. node.default[:unicorn][:preload_app] = false
  25. node.default[:unicorn][:before_fork] = 'sleep 1'
  26. node.default[:unicorn][:port] = '8080'
  27. node.set[:unicorn][:options] = { :tcp_nodelay => true, :backlog => 100 }
  28. unicorn_config "/etc/unicorn/#{app['id']}.rb" do
  29. listen({ node[:unicorn][:port] => node[:unicorn][:options] })
  30. worker_timeout node[:unicorn][:worker_timeout]
  31. preload_app node[:unicorn][:preload_app]
  32. worker_processes node[:unicorn][:worker_processes]
  33. before_fork node[:unicorn][:before_fork]
  34. end
  35. runit_service app['id'] do
  36. template_name 'unicorn'
  37. cookbook 'application'
  38. options(:app => app)
  39. run_restart false
  40. end
  41. if File.exists?(File.join(app['deploy_to'], "current"))
  42. d = resources(:deploy => app['id'])
  43. d.restart_command do
  44. execute "/etc/init.d/#{app['id']} hup"
  45. end
  46. end