ra-capistrano-recipes 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Webficient LLC, Phil Misiowiec
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,117 @@
1
+ =Capistrano Recipes
2
+
3
+ Useful Capistrano recipes including:
4
+
5
+ * Create MySQL database and user on server (via prompts)
6
+ * Create standalone copy of database.yml in shared path (via prompts)
7
+ * Log rotation and tailing commands
8
+ * Restart and profile Phusion Passenger application server
9
+ * Configure, start/stop/restart Unicorn application server
10
+ * Send commands to God or Bluepill monitoring tools
11
+ * Send commands to Thinking Sphinx
12
+
13
+ ==Included Tasks
14
+
15
+ * cap db:create_yaml
16
+ * cap db:mysql:setup
17
+ * cap db:mysql:dump
18
+ * cap db:mysql:fetch_dump
19
+ * cap db:mysql:restore
20
+ * cap log:rotate
21
+ * cap log:tail
22
+ * cap passenger:bounce
23
+ * cap passenger:memory
24
+ * cap passenger:status
25
+ * cap nginx:setup
26
+ * cap nginx:start
27
+ * cap nginx:stop
28
+ * cap nginx:restart
29
+ * cap nginx:status
30
+ * cap unicorn:start
31
+ * cap unicorn:stop
32
+ * cap unicorn:restart
33
+ * cap unicorn:setup
34
+ * cap symlinks:make
35
+ * cap god:setup
36
+ * cap god:implode
37
+ * cap god:restart
38
+ * cap god:reload
39
+ * cap god:status
40
+ * cap god:terminate
41
+ * cap god:start
42
+ * cap god:stop
43
+ * cap god:quit
44
+ * cap bluepill:install
45
+ * cap bluepill:init
46
+ * cap bluepill:start
47
+ * cap bluepill:restart
48
+ * cap bluepill:stop
49
+ * cap bluepill:status
50
+ * cap sphinx:config
51
+ * cap sphinx:start
52
+ * cap sphinx:stop
53
+ * cap sphinx:rebuild
54
+ * cap sphinx:index
55
+ * cap sphinx:symlinks
56
+
57
+ ==Installation
58
+
59
+ Easy as pie...
60
+
61
+ Ensure you have the Capistrano gem installed:
62
+
63
+ sudo gem install capistrano
64
+
65
+ Optionally install the Capistrano extensions gem to give you multistage support:
66
+
67
+ sudo gem install capistrano-ext
68
+
69
+ Install this gem:
70
+
71
+ sudo gem install capistrano-recipes --source=http://gemcutter.com
72
+
73
+ To setup the initial Capistrano deploy file, go to your Rails app folder via command line and enter:
74
+
75
+ capify .
76
+
77
+ ==Configuration
78
+
79
+ Inside the newly created config/deploy.rb, add:
80
+
81
+ require 'capistrano/ext/multistage' # only require if you've installed Cap ext gem
82
+
83
+ # This one should go at the end of your deploy.rb
84
+ require 'capistrano_recipes'
85
+
86
+ ===RVM
87
+
88
+ RVM is enabled by default. You can disable it by setting :using_rvm to false, or leverage it
89
+ by setting your rvm_ruby_string to appropriate ones (default is ree)
90
+
91
+ If using_rvm is true, the rvm recipe will load rvm's own capistrano extensions so you don't
92
+ have to worry about it during deploy. Just make sure you have everything set up right, like
93
+ .rvmrc on project root and system-wide install on the servers.
94
+
95
+ See (http://rvm.beginrescueend.com/rvm/install) for more info.
96
+
97
+ ===Nginx
98
+
99
+ If you're using nginx as your web server, set :web_server to :nginx and deploy:setup will
100
+ generate the appropriate configuration file for it based on your other variables, such as
101
+ :application_uses_ssl, etc.
102
+
103
+ ===Passenger
104
+
105
+ If you're running Phusion Passenger (http://www.modrails.com) be sure you add this line to config/deploy.rb:
106
+
107
+ set :server, :passenger
108
+
109
+ ===Unicorn
110
+
111
+ If you're running Unicorn (http://unicorn.bogomips.org/) be sure to add this line instead:
112
+
113
+ set :server, :unicorn
114
+
115
+ ==Copyright
116
+
117
+ Copyright (c) 2009 Webficient LLC, Phil Misiowiec. See LICENSE for details.
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ra-capistrano-recipes"
8
+ gem.summary = %Q{Darkside's Capistrano recipes}
9
+ gem.description = 'Extend the Capistrano gem with these useful recipes'
10
+ gem.email = "rogerio@depoiseuleio.com"
11
+ gem.homepage = "http://github.com/rogerio-augusto/capistrano-recipes"
12
+ gem.authors = ["Phil Misiowiec", "Leonardo Bighetti", "Rogério Augusto"]
13
+ gem.add_dependency('capistrano', ['>= 2.5.9'])
14
+ gem.add_dependency('capistrano-ext', ['>= 1.2.1'])
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
+ end
20
+
21
+ require 'rake/rdoctask'
22
+ Rake::RDocTask.new do |rdoc|
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = 'capistrano-recipes'
25
+ rdoc.options << '--line-numbers' << '--inline-source'
26
+ rdoc.rdoc_files.include('README*')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
@@ -0,0 +1,5 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 0
4
+ :build:
5
+ :minor: 7
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dark-capistrano-recipes}
8
+ s.version = "0.7.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Phil Misiowiec", "Leonardo Bighetti"]
12
+ s.date = %q{2011-02-09}
13
+ s.description = %q{Extend the Capistrano gem with these useful recipes}
14
+ s.email = %q{leonardobighetti@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "dark-capistrano-recipes.gemspec",
25
+ "doc/god/god",
26
+ "doc/god/god.conf",
27
+ "doc/god/god.init",
28
+ "generators/app.god.erb",
29
+ "generators/nginx.conf.erb",
30
+ "generators/unicorn.rb.erb",
31
+ "lib/capistrano_recipes.rb",
32
+ "lib/helpers.rb",
33
+ "lib/recipes/application.rb",
34
+ "lib/recipes/bluepill.rb",
35
+ "lib/recipes/bundler.rb",
36
+ "lib/recipes/db.rb",
37
+ "lib/recipes/deploy.rb",
38
+ "lib/recipes/god.rb",
39
+ "lib/recipes/hooks.rb",
40
+ "lib/recipes/log.rb",
41
+ "lib/recipes/nginx.rb",
42
+ "lib/recipes/passenger.rb",
43
+ "lib/recipes/resque.rb",
44
+ "lib/recipes/rvm.rb",
45
+ "lib/recipes/sphinx.rb",
46
+ "lib/recipes/symlinks.rb",
47
+ "lib/recipes/unicorn.rb"
48
+ ]
49
+ s.homepage = %q{http://github.com/darkside/capistrano-recipes}
50
+ s.require_paths = ["lib"]
51
+ s.rubygems_version = %q{1.5.0}
52
+ s.summary = %q{Darkside's Capistrano recipes}
53
+
54
+ if s.respond_to? :specification_version then
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
+ s.add_runtime_dependency(%q<capistrano>, [">= 2.5.9"])
59
+ s.add_runtime_dependency(%q<capistrano-ext>, [">= 1.2.1"])
60
+ else
61
+ s.add_dependency(%q<capistrano>, [">= 2.5.9"])
62
+ s.add_dependency(%q<capistrano-ext>, [">= 1.2.1"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<capistrano>, [">= 2.5.9"])
66
+ s.add_dependency(%q<capistrano-ext>, [">= 1.2.1"])
67
+ end
68
+ end
69
+
@@ -0,0 +1 @@
1
+ GOD_CONFIG=/etc/god/god.conf
@@ -0,0 +1,102 @@
1
+ APPS_ROOT = Dir.glob("/var/www/apps/*/current/config/app.god")
2
+
3
+ # Helper Methods
4
+ def unicorn(w, config, options = {})
5
+ rails_root = options[:rails_root]
6
+ rails_env = options[:rails_env] || 'production'
7
+ unicorn_group = options[:app] || options[:name] || 'default'
8
+ unicorn_name = "#{unicorn_group}-unicorn"
9
+ unicorn_bin = options[:bin_unicorn] || 'bootup_unicorn_rails'
10
+ unicorn_pid = options[:unicorn_pid] || "#{rails_root}/log/unicorn.pid"
11
+ unicorn_config = "#{rails_root}/config/unicorn.rb"
12
+ unicorn_start = options[:start_cmd] || "cd #{rails_root} && #{unicorn_bin} -c #{unicorn_config} -E #{rails_env} -D"
13
+ # QUIT gracefully shuts down workers
14
+ unicorn_stop = options[:stop_cmd] || "kill -QUIT `cat #{unicorn_pid}`"
15
+ # USR2 causes the master to re-create itself and spawn a new worker pool
16
+ unicorn_restart = options[:restart_cmd] || "kill -USR2 `cat #{unicorn_pid}`"
17
+
18
+
19
+ w.name = unicorn_name
20
+ w.group = unicorn_group
21
+ w.start = unicorn_start
22
+ w.stop = unicorn_stop
23
+ w.restart = unicorn_restart
24
+ w.start_grace = 20.seconds
25
+ w.restart_grace = 20.seconds
26
+ w.pid_file = unicorn_pid
27
+ w.behavior(:clean_pid_file)
28
+
29
+ generic_monitor(w, config, rails_root, options)
30
+ end
31
+
32
+ def generic_monitor(w, config, rails_root, options = {})
33
+ w.uid = options[:user] || 'deploy'
34
+ w.gid = options[:group] || 'www-data'
35
+ w.interval = 60.seconds # default
36
+
37
+ # determine the state on startup
38
+ w.transition(:init, { true => :up, false => :start }) do |on|
39
+ on.condition(:process_running) do |c|
40
+ c.running = true
41
+ end
42
+ end
43
+
44
+ # determine when process has finished starting
45
+ w.transition([:start, :restart], :up) do |on|
46
+ on.condition(:process_running) do |c|
47
+ c.running = true
48
+ end
49
+
50
+ # failsafe
51
+ on.condition(:tries) do |c|
52
+ c.times = 5
53
+ c.transition = :start
54
+ end
55
+ end
56
+
57
+ # start if process is not running
58
+ w.transition(:up, :start) do |on|
59
+ on.condition(:process_exits) do |c|
60
+ end
61
+ end
62
+
63
+ # restart if memory or cpu is too high
64
+ w.transition(:up, :restart) do |on|
65
+ on.condition(:memory_usage) do |c|
66
+ c.interval = 20
67
+ c.above = options[:memory_limit] || 150.megabytes
68
+ c.times = [3, 5]
69
+ end
70
+
71
+ on.condition(:cpu_usage) do |c|
72
+ c.interval = 20
73
+ c.above = options[:cpu_limit] || 50.percent
74
+ c.times = [3, 5]
75
+ end
76
+ end
77
+
78
+ # lifecycle
79
+ w.lifecycle do |on|
80
+ on.condition(:flapping) do |c|
81
+ c.to_state = [:start, :restart]
82
+ c.times = 5
83
+ c.within = 5.minute
84
+ c.transition = :unmonitored
85
+ c.retry_in = 10.minutes
86
+ c.retry_times = 5
87
+ c.retry_within = 2.hours
88
+ end
89
+ end
90
+ end
91
+
92
+ God.log_level = :info
93
+ puts "God is loading the apps now..."
94
+ APPS_ROOT.each do |app|
95
+ begin
96
+ puts "Loading app: #{app}"
97
+ God.load app
98
+ puts "Done"
99
+ rescue Exception => e
100
+ puts "Failed! #{e}"
101
+ end
102
+ end
@@ -0,0 +1,62 @@
1
+ #!/bin/sh
2
+
3
+ ### BEGIN INIT INFO
4
+ # Provides: god
5
+ # Required-Start: $all
6
+ # Required-Stop: $all
7
+ # Default-Start: 2 3 4 5
8
+ # Default-Stop: 0 1 6
9
+ # Short-Description: God
10
+ ### END INIT INFO
11
+
12
+ NAME=god
13
+ DESC=god
14
+
15
+ GOD_BIN=/usr/local/bin/bootup_god
16
+ GOD_PID=/var/run/god.pid
17
+ GOD_LOG=/var/log/god.log
18
+ set -e
19
+
20
+ # Make sure the binary and the config file are present before proceeding
21
+ test -x $GOD_BIN || exit 0
22
+
23
+ # Create this file and put in a variable called GOD_CONFIG, pointing to
24
+ # your God configuration file
25
+ test -f /etc/default/god && . /etc/default/god
26
+ [ $GOD_CONFIG ] || exit 0
27
+
28
+ . /lib/lsb/init-functions
29
+
30
+ RETVAL=0
31
+
32
+ case "$1" in
33
+ start)
34
+ echo -n "Starting $DESC: "
35
+ $GOD_BIN -c $GOD_CONFIG -P $GOD_PID -l $GOD_LOG
36
+ RETVAL=$?
37
+ echo "$NAME."
38
+ ;;
39
+ stop)
40
+ echo -n "Stopping $DESC: "
41
+ kill `cat $GOD_PID`
42
+ RETVAL=$?
43
+ echo "$NAME."
44
+ ;;
45
+ restart)
46
+ echo -n "Restarting $DESC: "
47
+ kill `cat $GOD_PID`
48
+ $GOD_BIN -c $GOD_CONFIG -P $GOD_PID -l $GOD_LOG
49
+ RETVAL=$?
50
+ echo "$NAME."
51
+ ;;
52
+ status)
53
+ $GOD_BIN status
54
+ RETVAL=$?
55
+ ;;
56
+ *)
57
+ echo "Usage: god {start|stop|restart|status}"
58
+ exit 1
59
+ ;;
60
+ esac
61
+
62
+ exit $RETVAL
@@ -0,0 +1,25 @@
1
+ app_name = '<%= application %>'
2
+ rails_root = '<%= deploy_to %>/current'
3
+ unicorn_bin = '<%= unicorn_bin %>'
4
+ unicorn_pid = '<%= unicorn_pid %>'
5
+ unicorn_config = '<%= unicorn_remote_config %>'
6
+ unicorn_start_cmd = '<%= unicorn_start_cmd %>'
7
+ unicorn_stop_cmd = '<%= unicorn_stop_cmd %>'
8
+ unicorn_restart_cmd = '<%= unicorn_restart_cmd %>'
9
+
10
+ # Unicorn
11
+ God.watch do |w|
12
+ unicorn(w, rails_root,
13
+ :memory_limit => 100.megabytes,
14
+ :cpu_limit => 50.percent,
15
+ :bin_unicorn => unicorn_bin,
16
+ :name => app_name,
17
+ :rails_root => rails_root,
18
+ :unicorn_conf => unicorn_config,
19
+ :unicorn_pid => unicorn_pid,
20
+ :start_cmd => unicorn_start_cmd,
21
+ :stop_cmd => unicorn_stop_cmd,
22
+ :restart_cmd => unicorn_restart_cmd,
23
+ :user => '<%= unicorn_user %>',
24
+ :group => '<%= unicorn_group %>')
25
+ end
@@ -0,0 +1,207 @@
1
+ <% if is_using_unicorn %>
2
+ upstream <%= application %>_app_server {
3
+ server unix:<%= unicorn_socket %> fail_timeout=0;
4
+ }
5
+ <% end %>
6
+ # <%= application %> Server
7
+ server {
8
+ listen <%= application_port %>;
9
+ <% if is_using_passenger %>
10
+ rails_env <%= rails_env %>;
11
+ passenger_enabled on;
12
+ <% end %>
13
+ client_max_body_size 500M;
14
+ server_name <%= application %>;
15
+
16
+ # ~2 seconds is often enough for most folks to parse HTML/CSS and
17
+ # retrieve needed images/icons/frames, connections are cheap in
18
+ # nginx so increasing this is generally safe...
19
+ keepalive_timeout 5;
20
+
21
+ # path for static files
22
+ root <%= deploy_to %>/current/public;
23
+ access_log <%= deploy_to %>/current/log/nginx.access.log main;
24
+ error_log <%= deploy_to %>/current/log/nginx.error.log info;
25
+
26
+ # this rewrites all the requests to the maintenance.html
27
+ # page if it exists in the doc root. This is for capistrano's
28
+ # disable web task
29
+ if (-f $document_root/system/maintenance.html) {
30
+ rewrite ^(.*)$ /system/maintenance.html last;
31
+ break;
32
+ }
33
+
34
+ location / {
35
+ <% if is_using_passenger %>
36
+ rails_env <%= rails_env %>;
37
+ passenger_enabled on;
38
+ <% end %>
39
+
40
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
41
+ proxy_set_header Host $http_host;
42
+
43
+ # If the file exists as a static file serve it directly without
44
+ # running all the other rewite tests on it
45
+ if (-f $request_filename) {
46
+ break;
47
+ }
48
+
49
+ # check for index.html for directory index
50
+ # if its there on the filesystem then rewite
51
+ # the url to add /index.html to the end of it
52
+ # and then break to send it to the next config rules.
53
+ if (-f $request_filename/index.html) {
54
+ rewrite (.*) $1/index.html break;
55
+ }
56
+
57
+ # this is the meat of the rails page caching config
58
+ # it adds .html to the end of the url and then checks
59
+ # the filesystem for that file. If it exists, then we
60
+ # rewite the url to have explicit .html on the end
61
+ # and then send it on its way to the next config rule.
62
+ # if there is no file on the fs then it sets all the
63
+ # necessary headers and proxies to our upstream mongrels
64
+ if (-f $request_filename.html) {
65
+ rewrite (.*) $1.html break;
66
+ }
67
+
68
+ <% if is_using_unicorn %>
69
+ if (!-f $request_filename) {
70
+ proxy_pass http://<%= application %>_app_server;
71
+ break;
72
+ }
73
+ <% end %>
74
+ }
75
+
76
+ # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
77
+ # BUT there's a chance it could break the ajax calls.
78
+ location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
79
+ expires max;
80
+ break;
81
+ }
82
+
83
+ location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
84
+ expires max;
85
+ break;
86
+ }
87
+
88
+ # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
89
+ # BUT there's a chance it could break the ajax calls.
90
+ location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
91
+ expires max;
92
+ break;
93
+ }
94
+
95
+ location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
96
+ expires max;
97
+ break;
98
+ }
99
+
100
+ # if the request is for a static resource, nginx should serve it directly
101
+ # and add a far future expires header to it, making the browser
102
+ # cache the resource and navigate faster over the website
103
+ location ~ ^/(images|javascripts|stylesheets|system)/ {
104
+ root /home/deployer/shop/current/public;
105
+ expires max;
106
+ break;
107
+ }
108
+
109
+ # Rails error pages
110
+ error_page 500 502 503 504 /500.html;
111
+ location = /500.html {
112
+ root <%= deploy_to %>/current/public;
113
+ }
114
+ }
115
+
116
+ <% if application_uses_ssl %>
117
+
118
+ <% if is_using_unicorn %>
119
+ upstream <%= application %>_app_ssl {
120
+ server unix:<%= unicorn_socket %> fail_timeout=0;
121
+ }
122
+ <% end %>
123
+
124
+ # This server is setup for ssl. Uncomment if
125
+ # you are using ssl as well as port 80.
126
+ server {
127
+ listen <%= application_port_ssl%>;
128
+ server_name <%= application %>;
129
+ <% if is_using_passenger %>
130
+ rails_env <%= rails_env %>;
131
+ passenger_enabled on;
132
+ <% end %>
133
+ ssl on;
134
+ ssl_certificate /etc/ssl/certs/server.crt;
135
+ ssl_certificate_key /etc/ssl/private/server.key;
136
+ ssl_session_timeout 5m;
137
+ client_max_body_size 50M;
138
+
139
+ root <%= deploy_to %>/current/public;
140
+ access_log <%= deploy_to %>/current/log/nginx.access.log main;
141
+ error_log <%= deploy_to %>/current/log/nginx.error.log info;
142
+
143
+ # this rewrites all the requests to the maintenance.html
144
+ # page if it exists in the doc root. This is for capistrano's
145
+ # disable web task
146
+ if (-f $document_root/system/maintenance.html) {
147
+ rewrite ^(.*)$ /system/maintenance.html last;
148
+ break;
149
+ }
150
+
151
+ location / {
152
+ <% if is_using_passenger %>
153
+ rails_env <%= rails_env %>;
154
+ passenger_enabled on;
155
+ <% end %>
156
+
157
+ # needed to forward user's IP address to rails
158
+ proxy_set_header X-Real-IP $remote_addr;
159
+
160
+ # needed for HTTPS
161
+ proxy_set_header X_FORWARDED_PROTO https;
162
+
163
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
164
+ proxy_set_header Host $http_host;
165
+ proxy_redirect off;
166
+ proxy_max_temp_file_size 0;
167
+
168
+
169
+ # If the file exists as a static file serve it directly without
170
+ # running all the other rewite tests on it
171
+ if (-f $request_filename) {
172
+ break;
173
+ }
174
+
175
+ # check for index.html for directory index
176
+ # if its there on the filesystem then rewite
177
+ # the url to add /index.html to the end of it
178
+ # and then break to send it to the next config rules.
179
+ if (-f $request_filename/index.html) {
180
+ rewrite (.*) $1/index.html break;
181
+ }
182
+
183
+ # this is the meat of the rails page caching config
184
+ # it adds .html to the end of the url and then checks
185
+ # the filesystem for that file. If it exists, then we
186
+ # rewite the url to have explicit .html on the end
187
+ # and then send it on its way to the next config rule.
188
+ # if there is no file on the fs then it sets all the
189
+ # necessary headers and proxies to our upstream mongrels
190
+ if (-f $request_filename.html) {
191
+ rewrite (.*) $1.html break;
192
+ }
193
+
194
+ <% if is_using_unicorn %>
195
+ if (!-f $request_filename) {
196
+ proxy_pass http://<%= application %>_app_ssl;
197
+ break;
198
+ }
199
+ <% end %>
200
+ }
201
+
202
+ error_page 500 502 503 504 /500.html;
203
+ location = /500.html {
204
+ root <%= deploy_to %>/current/public;
205
+ }
206
+ }
207
+ <% end %>