gunicorn.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #
  2. # Cookbook Name:: application
  3. # Recipe:: gunicorn
  4. #
  5. # Copyright 2011, 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::gunicorn recipe is deprecated and will go away on Aug 1st. See the README for migration information."
  20. app = node.run_state[:current_app]
  21. ve = resources(:python_virtualenv => app['id'])
  22. node.default[:gunicorn][:virtualenv] = ve.path
  23. include_recipe "gunicorn"
  24. node.default[:gunicorn][:worker_timeout] = 60
  25. node.default[:gunicorn][:preload_app] = false
  26. node.default[:gunicorn][:worker_processes] = [node[:cpu][:total].to_i * 4, 8].min
  27. node.default[:gunicorn][:server_hooks] = {:pre_fork => 'import time;time.sleep(1)'}
  28. node.default[:gunicorn][:port] = '8080'
  29. gunicorn_config "/etc/gunicorn/#{app['id']}.py" do
  30. listen "#{node[:ipaddress]}:#{node[:gunicorn][:port]}"
  31. worker_timeout node[:gunicorn][:worker_timeout]
  32. preload_app node[:gunicorn][:preload_app]
  33. worker_processes node[:gunicorn][:worker_processes]
  34. server_hooks node[:gunicorn][:server_hooks]
  35. action :create
  36. end
  37. runit_service app['id'] do
  38. template_name 'gunicorn'
  39. cookbook 'application'
  40. options('app' => app, 'virtualenv' => ve.path)
  41. run_restart false
  42. end
  43. if ::File.exists?(::File.join(app['deploy_to'], "current"))
  44. d = resources(:deploy_revision => app['id'])
  45. d.restart_command do
  46. execute "/etc/init.d/#{app['id']} hup"
  47. end
  48. end