adamhjk (owner)

Revisions

gist: 228850 Download_button fork
public
Public Clone URL: git://gist.github.com/228850.git
Embed All Files: show embed
rails_nginx_ree_passenger.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    ## Then, deploy
    deploy_revision app['id'] do
      revision app['revision'][node.app_environment]
      repository app['repository']
      user app['owner']
      group app['group']
      deploy_to app['deploy_to']
      action app['force'][node.app_environment] ? :force_deploy : :deploy
      ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
      if app['migrate'][node.app_environment] && node[:apps][app['id']][node.app_environment][:run_migrations]
        migrate true
        migration_command "rake db:migrate"
      else
        migrate false
      end
      restart_command do
        case app["type"]
        when /nginx/
          service "nginx" do action :restart; end
        when /apache/
          service "apache" do action :restart; end
        end
      end
      symlink_before_migrate({ "database.yml" => "config/database.yml" })
      before_symlink do
        if app["database_master_role"]
          results = search(:node, "run_list:role\\[#{app["database_master_role"][0]}\\]", nil, 0, 1)
          rows = results[0]
          if rows.length == 1
            dbm = rows[0]
            template "#{@new_resource.shared_path}/database.yml" do
              source "database.yml.erb"
              owner app["owner"]
              group app["group"]
              mode "644"
              variables(
                :host => dbm['fqdn'],
                :databases => app['databases']
              )
            end
          else
            Chef::Log.warn("No node with role #{app["database_master_role"][0]}, database.yml not rendered!")
          end
        end
      end
    end