adamhjk (owner)

Forks

Revisions

gist: 215543 Download_button fork
public
Public Clone URL: git://gist.github.com/215543.git
Embed All Files: show embed
apps/monkeynews.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "server_roles": [
    "monkeynews"
  ],
  "database_slave_role": [
    "monkeynews_database_slave"
  ],
  "repository": "git@github.com:adamhjk\/monkeynews.git",
  "database_master_role": [
    "monkeynews_database_master"
  ],
  "type": "rails_nginx_ree_passenger",
  "revision": {
    "production": "12345"
  },
  "id": "monkeynews",
  "deploy_to": "\/srv\/monkeynews",
  "owner": "root",
  "gems": {
    "right_aws": "1.10.0"
  },
  "group": "root"
}
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#
# Cookbook Name:: application
# Recipe:: default
#
# Copyright 2009, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
 
include_recipe "ruby_enterprise"
 
runit_service "nginx"
 
search(:apps) do |app|
  if (app["server_roles"] & node.run_list.roles).length > 0
    
    ## First, install any custom rubygems
    if app['gems']
      app['gems'].each do |gem,ver|
        ree_gem gem do
          version ver
        end
      end
    end
 
    ## Then, configure nginx
    template "#{node[:nginx][:dir]}/sites-available/#{app['id']}.conf" do
      source "#{app['id']}.conf.erb"
      owner "root"
      group "root"
      mode "0644"
      variables(
        :app => app['id'],
        :docroot => "/srv/#{app['id']}/current/public",
        :server_name => "#{app['id']}.#{node[:domain]}",
        :server_aliases => [ node[:fqdn], a['id'] ],
        :rails_env => a['environment']
      )
    end
 
    nginx_site "#{app['id']}.conf" do
      notifies :restart, resources(:service => "nginx")
    end
 
    ## Then, deploy
    deploy_revision app['id'] do
      revision app['revision'][node.app_environment]
      repository app['repository']
      user app['user']
      group app['group']
      deploy_to app['deploy_to']
      restart_command do
        case app["type"]
        when /nginx/
          service "nginx" { action :restart }
        when /apache/
          service "apache" { action :restart }
        end
      end
      before_symlink do
        if app["database_master_role"]
          dbm = search(:node, app["database_master_role"].join(" OR "), nil, 0, 1)["rows"].first
          template "#{release_path}/config/database.yml" do
            source "database.yml.erb"
            owner app["owner"]
            group app["group"]
            mode "600"
            variables(
              :database => "#{app['id']}_#{node.app_environment}",
              :adapter => app['db_type'],
              :user => app['owner'],
              :password => app['password'],
              :host => dbm['hostname']
            )
          end
        end
      end
    end
  end
end