From 32697d511ccdee80b2950665937c1c751e31ebc5 Mon Sep 17 00:00:00 2001 From: itsystem Date: Thu, 13 Oct 2016 15:35:15 +0800 Subject: [PATCH] Create rails_new.rb --- unicorn/recipes/rails_new.rb | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 unicorn/recipes/rails_new.rb diff --git a/unicorn/recipes/rails_new.rb b/unicorn/recipes/rails_new.rb new file mode 100644 index 0000000000..9f06cc32da --- /dev/null +++ b/unicorn/recipes/rails_new.rb @@ -0,0 +1,52 @@ +unless node[:opsworks][:skip_uninstall_of_other_rails_stack] + include_recipe "apache2::uninstall" +end + +include_recipe "nginx" +include_recipe "unicorn" + +# setup Unicorn service per app +node[:deploy].each do |application, deploy| + if deploy[:application_type] != 'rails' + Chef::Log.debug("Skipping unicorn::rails application #{application} as it is not an Rails app") + next + end + + opsworks_deploy_user do + deploy_data deploy + end + + opsworks_deploy_dir do + user deploy[:user] + group deploy[:group] + path deploy[:deploy_to] + end + + template "#{deploy[:deploy_to]}/shared/scripts/unicorn" do + mode '0755' + owner deploy[:user] + group deploy[:group] + source "unicorn.service.erb" + variables(:deploy => deploy, :application => application) + end + + service "unicorn_#{application}" do + start_command "#{deploy[:deploy_to]}/shared/scripts/unicorn start" + stop_command "#{deploy[:deploy_to]}/shared/scripts/unicorn stop" + restart_command "#{deploy[:deploy_to]}/shared/scripts/unicorn restart" + status_command "#{deploy[:deploy_to]}/shared/scripts/unicorn status" + action :nothing + end + + template "#{deploy[:deploy_to]}/shared/config/unicorn.conf" do + mode '0644' + owner deploy[:user] + group deploy[:group] + source "unicorn.conf.erb" + variables( + :deploy => deploy, + :application => application, + :environment => OpsWorks::Escape.escape_double_quotes(deploy[:environment_variables]) + ) + end +end