-
Notifications
You must be signed in to change notification settings - Fork 0
/
NonRails-Recipe.rb
125 lines (104 loc) · 3.88 KB
/
NonRails-Recipe.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# =========================================================================
# These are the tasks that are available to help with deploying web apps,
# and specifically, NON Rails applications. You can have cap give you a summary
# of them with `cap -T'.
# =========================================================================
namespace :deploy do
desc <<-DESC
[Overload] Deploys your project. This calls `update'. Note that \
this will generally only work for applications that have already been deployed \
once. For a "cold" deploy, you'll want to take a look at the `deploy:cold' \
task, which handles the cold start specifically.
DESC
task :default do
update
end
desc <<-DESC
[Overload] Touches up the released code. This is called by update_code \
after the basic deploy finishes.
This method should be overridden to meet the requirements of your allocation.
DESC
task :finalize_update, :except => { :no_release => true } do
#
end
desc <<-DESC
[Overload] Default actions cancelled
DESC
task :restart, :roles => :app, :except => { :no_release => true } do
#
end
desc <<-DESC
[Overload] Default actions cancelled.
DESC
task :migrate, :roles => :db, :only => { :primary => true } do
#
end
desc <<-DESC
[Overload] Default actions cancelled.
DESC
task :migrations do
set :migrate_target, :latest
#
end
desc <<-DESC
[Overload] Default actions only calls 'update'.
DESC
task :cold do
update
end
desc <<-DESC
[Overload] Default actions cancelled.
DESC
task :start, :roles => :app do
#
end
desc <<-DESC
[Overload] Default actions cancelled.
DESC
task :stop, :roles => :app do
#
end
namespace :web do
desc <<-DESC
Present a maintenance page to visitors. Disables your application's web \
interface by writing a "maintenance.html" file to each web server. The \
servers must be configured to detect the presence of this file, and if \
it is present, always display it instead of performing the request.
By default, the maintenance page will just say the site is down for \
"maintenance", and will be back "shortly", but you can customize the \
page by specifying the REASON and UNTIL environment variables:
$ cap deploy:web:disable \\
REASON="hardware upgrade" \\
UNTIL="12pm Central Time"
Further customization will require that you write your own task.
DESC
task :disable, :roles => :web, :except => { :no_release => true } do
require 'erb'
on_rollback { run "rm #{shared_path}/system/maintenance.html" }
warn <<-EOHTACCESS
# Please add something like this to your site's htaccess to redirect users to the maintenance page.
# More Info: http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
ErrorDocument 503 /system/maintenance.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ - [redirect=503,last]
EOHTACCESS
reason = ENV['REASON']
deadline = ENV['UNTIL']
template = File.read(File.join(File.dirname(__FILE__), "templates", "maintenance.rhtml"))
result = ERB.new(template).result(binding)
put result, "#{shared_path}/system/maintenance.html", :mode => 0644
end
desc <<-DESC
Makes the application web-accessible again. Removes the \
"maintenance.html" page generated by deploy:web:disable, which (if your \
web servers are configured correctly) will make your application \
web-accessible again.
DESC
task :enable, :roles => :web, :except => { :no_release => true } do
run "rm #{shared_path}/system/maintenance.html"
end
end
end