capify-php 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tass Skoudros
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.
data/README.markdown ADDED
@@ -0,0 +1,133 @@
1
+ # capify-php
2
+
3
+ * capify-php - is a Capistrano extension for PHP without the *rails* tasks.
4
+
5
+ ## Benefits
6
+
7
+ capify-php is simple to install, it cleanly extends Capistrano, keeping your deploy.rb tidy.
8
+
9
+
10
+ ## Features
11
+
12
+ * Same rollback you get from Capistrano
13
+ * Easy to configure
14
+ * Supports exporting PHP libraries from any Git source
15
+ * Setup multiple environments with tasks inside your deploy.rb. (example below)
16
+
17
+ ## Installation
18
+
19
+ If you don't have capistrano and/or capify-php installed:
20
+
21
+ # gem install capistrano
22
+ # gem install capify-php -s http://gemcutter.org
23
+
24
+ For every application you'll want to deploy:
25
+
26
+ # cd /path/to/app && capify .
27
+
28
+ This will create the following files in your project (don't forget to commit them!):
29
+
30
+ capfile
31
+ config/deploy.rb
32
+
33
+ Prepend your config/deploy.rb with the following lines:
34
+
35
+ require 'rubygems'
36
+ require 'capify-php'
37
+
38
+ And make sure you start capify-php on the last line of that same file:
39
+
40
+ capify-php
41
+
42
+ You should then be able to proceed as you usually would. To familiarise yourself with the now modified list of tasks, you can get a full list with:
43
+
44
+ $ cap -T
45
+
46
+ ## Configuration
47
+
48
+ Before continuing, some changes to config/deploy.rb are necessary. First, your project's name:
49
+
50
+ set :application, "your_app_name"
51
+
52
+ Next, setting up the Git repository (make sure it's accessible by both your local machine and server your are deploying to):
53
+
54
+ set :repository, "git@domain.com:path/to/repo"
55
+
56
+ Now, to deploy from Git, and by following [GitHub's suggestion](http://github.com/guides/deploying-with-capistrano) (they must know what they are talking about), add a user (defaults to *deploy* by capistrano.php's recipe) to your server(s) just for deployments. In this example, I will be using SSH keys instead of getting a Git password prompt. Local user's SSH key must be added to *deploy*'s ~/.ssh/authorized_keys for this to work as described.
57
+
58
+ ssh_options[:forward_agent] = true
59
+
60
+ We need to tell it where to deploy, using what methods:
61
+
62
+
63
+ You can change the default values for the following variables also:
64
+
65
+ set :php_lib_branch, "v2.0.1"
66
+ set :php_lib_repo, "https://github.com/symfony/symfony.git"
67
+ set :php_lib_dir, "symfony"
68
+
69
+ ## Deployment
70
+
71
+ The first time you are deploying, you need to run:
72
+
73
+ # cap deploy:setup
74
+
75
+ That should create on your server the following directory structure:
76
+
77
+ [deploy_to]
78
+ [deploy_to]/releases
79
+ [deploy_to]/shared
80
+ [deploy_to]/shared/cakephp
81
+ [deploy_to]/shared/system
82
+ [deploy_to]/shared/tmp
83
+
84
+ Finally, deploy:
85
+
86
+ # cap deploy
87
+
88
+ Which will change the directory structure to become:
89
+
90
+ [deploy_to]
91
+ [deploy_to]/current -> [deploy_to]/releases/20091013001122
92
+ [deploy_to]/releases
93
+ [deploy_to]/releases/20091013001122
94
+ [deploy_to]/releases/20091013001122/system -> [deploy_to]/shared/system
95
+ [deploy_to]/releases/20091013001122/tmp -> [deploy_to]/shared/tmp
96
+ [deploy_to]/shared
97
+ [deploy_to]/shared/cakephp
98
+ [deploy_to]/shared/system
99
+ [deploy_to]/shared/tmp
100
+
101
+ ## Multiple environments 1 deploy.rb
102
+
103
+ desc "Run tasks in production enviroment."
104
+ task :production do
105
+ # Production nodes
106
+ role :web, "webserver-one-hostname-or-ip"
107
+ role :app, "webserver-one-hostname-or-ip"
108
+ role :web, "webserver-two-hostname-or-ip"
109
+ role :app, "webserver-two-hostname-or-ip"
110
+ set :branch, "master"
111
+ end
112
+
113
+ desc "Run tasks in staging enviroment."
114
+ task :staging do
115
+ # Staging nodes
116
+ role :web, "staging-hostname"
117
+ role :app, "staging-hostname"
118
+ role :db, "staging-hostname", :primary=>true
119
+ set :branch, "develop"
120
+ end
121
+
122
+
123
+ ## Patches & Features
124
+
125
+ * Fork
126
+ * Mod, fix
127
+ * Test - this is important, so it's not unintentionally broken
128
+ * Commit - do not mess with license, todo, version, etc. (if you do change any, make them into commits of their own that I can ignore when I pull)
129
+ * Pull request - bonus point for topic branches
130
+
131
+ ## Bugs & Feedback
132
+
133
+ http://github.com/askoudros/capify-php/issues
data/README.rdoc ADDED
@@ -0,0 +1,103 @@
1
+ # capistrano.php
2
+
3
+ Deploy a PHP based web application with Capistrano, Capistrano PHP is Capistrano without the *rails* finalisers. It is built to load your source and a extra php library using these extra variables in your deploy.rb.
4
+
5
+ set :php_lib_branch, ""
6
+ set :php_lib_repo, ""
7
+ set :php_lib_dir, ""
8
+
9
+ ## Installation
10
+
11
+ If you don't have Capistrano and/or Capistrano.PHP installed:
12
+
13
+ # gem install capistrano
14
+ # gem install capistrano.php -s http://gemcutter.org
15
+
16
+ For every application you'll want to deploy:
17
+
18
+ # cd /path/to/app && capify .
19
+
20
+ This will create the following files in your project (don't forget to commit them!):
21
+
22
+ capfile
23
+ config/deploy.rb
24
+
25
+ Prepend your config/deploy.rb with the following lines:
26
+
27
+ require 'rubygems'
28
+ require 'capistrano.php'
29
+
30
+ And make sure you start capcake on the last line of that same file:
31
+
32
+ capistrano.php
33
+
34
+ You should then be able to proceed as you usually would. To familiarize yourself with the now modified list of tasks, you can get a full list with:
35
+
36
+ $ cap -T
37
+
38
+ ## Configuration
39
+
40
+ Before continuing, some changes to config/deploy.rb are necessary. First, your project's name:
41
+
42
+ set :application, "your_app_name"
43
+
44
+ Next, setting up the Git repository (make sure it's accessible by both your local machine and server your are deploying to):
45
+
46
+ set :repository, "git@domain.com:path/to/repo"
47
+
48
+ Now, to deploy from Git, and by following [GitHub's suggestion](http://github.com/guides/deploying-with-capistrano) (they must know what they are talking about), add a user (defaults to *deploy* by capistrano.php's recipe) to your server(s) just for deployments. In this example, I will be using SSH keys instead of getting a Git password prompt. Local user's SSH key must be added to *deploy*'s ~/.ssh/authorized_keys for this to work as described.
49
+
50
+ ssh_options[:forward_agent] = true
51
+
52
+ We need to tell it where to deploy, using what methods:
53
+
54
+
55
+ You can change the default values for the following variables also:
56
+
57
+ set :php_lib_branch, "v2.0.1"
58
+ set :php_lib_repo, "https://github.com/symfony/symfony.git"
59
+ set :php_lib_dir, "symfony"
60
+
61
+ ## Deployment
62
+
63
+ The first time you are deploying, you need to run:
64
+
65
+ # cap deploy:setup
66
+
67
+ That should create on your server the following directory structure:
68
+
69
+ [deploy_to]
70
+ [deploy_to]/releases
71
+ [deploy_to]/shared
72
+ [deploy_to]/shared/cakephp
73
+ [deploy_to]/shared/system
74
+ [deploy_to]/shared/tmp
75
+
76
+ Finally, deploy:
77
+
78
+ # cap deploy
79
+
80
+ Which will change the directory structure to become:
81
+
82
+ [deploy_to]
83
+ [deploy_to]/current -> [deploy_to]/releases/20091013001122
84
+ [deploy_to]/releases
85
+ [deploy_to]/releases/20091013001122
86
+ [deploy_to]/releases/20091013001122/system -> [deploy_to]/shared/system
87
+ [deploy_to]/releases/20091013001122/tmp -> [deploy_to]/shared/tmp
88
+ [deploy_to]/shared
89
+ [deploy_to]/shared/cakephp
90
+ [deploy_to]/shared/system
91
+ [deploy_to]/shared/tmp
92
+
93
+ ## Patches & Features
94
+
95
+ * Fork
96
+ * Mod, fix
97
+ * Test - this is important, so it's not unintentionally broken
98
+ * Commit - do not mess with license, todo, version, etc. (if you do change any, make them into commits of their own that I can ignore when I pull)
99
+ * Pull request - bonus point for topic branches
100
+
101
+ ## Bugs & Feedback
102
+
103
+ http://github.com/askoudros/capistrano.php/issues
data/lib/capify-php.rb ADDED
@@ -0,0 +1,495 @@
1
+ # capify-php Rakefile
2
+ #
3
+ # Author:: Tass Skoudros (mailto:tass@skystack.com)
4
+ # Copyright:: Copyright (c) 2010, Skystack, Limited (http://www.skystack.com)
5
+ # License::
6
+
7
+ Capistrano::Configuration.instance(:must_exist).load do
8
+
9
+ require 'capistrano/recipes/deploy/scm'
10
+ require 'capistrano/recipes/deploy/strategy'
11
+
12
+ # =========================================================================
13
+ # These variables may be set in the client capfile if their default values
14
+ # are not sufficient.
15
+ # =========================================================================
16
+
17
+ set :application, ""
18
+ set :branch, "master"
19
+ set :deploy_to, ""
20
+ set :keep_releases, 5
21
+ set :repository, ""
22
+ set :use_sudo, false
23
+ set :user, "deploy"
24
+
25
+ # =========================================================================
26
+ # These variables should NOT be changed unless you are very confident in
27
+ # what you are doing. Make sure you understand all the implications of your
28
+ # changes if you do decide to muck with these!
29
+ # =========================================================================
30
+
31
+ set :scm, :git
32
+ set :git_enable_submodules, 1
33
+ set :revision, source.head
34
+ set :deploy_via, :checkout
35
+ set :shared_children, %w(config lib tmp)
36
+
37
+ set :git_flag_quiet, ""
38
+
39
+ _cset(:php_lib_branch) { "" }
40
+ _cset(:php_lib_repo) { "" }
41
+ _cset(:php_lib_dir) { "" }
42
+
43
+ _cset :tmp_children, %w(cache logs sessions tests)
44
+ _cset :cache_children, %w(models persistent views)
45
+ _cset :logs_files, %w(debug error)
46
+
47
+ def capify_php()
48
+ set :deploy_to, "/var/www/#{application}" if (deploy_to.empty?)
49
+ set(:current_path) { File.join(deploy_to, current_dir) }
50
+
51
+ set(:shared_path) { File.join(deploy_to, shared_dir) }
52
+ _cset(:php_lib_path) { shared_path }
53
+ _cset(:tmp_path) { File.join(shared_path, "tmp") }
54
+ _cset(:cache_path) { File.join(tmp_path, "cache") }
55
+ _cset(:logs_path) { File.join(tmp_path, "logs") }
56
+
57
+ after("deploy:setup", "php:database:config") if (!remote_file_exists?(database_path))
58
+ after("deploy:symlink", "php:database:symlink") if (remote_file_exists?(database_path))
59
+ end
60
+
61
+ def defaults(val, default)
62
+ val = default if (val.empty?)
63
+ val
64
+ end
65
+
66
+ def remote_file_exists?(full_path)
67
+ 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
68
+ end
69
+
70
+ # =========================================================================
71
+ # These are the tasks that are available to help with deploying web apps,
72
+ # and specifically, Rails applications. You can have cap give you a summary
73
+ # of them with `cap -T'.
74
+ # =========================================================================
75
+
76
+ namespace :deploy do
77
+ desc <<-DESC
78
+ Deploys your project. This calls `update'. Note that \
79
+ this will generally only work for applications that have already been deployed \
80
+ once. For a "cold" deploy, you'll want to take a look at the `deploy:cold' \
81
+ task, which handles the cold start specifically.
82
+ DESC
83
+ task :default do
84
+ update
85
+ end
86
+ desc <<-DESC
87
+ Prepares one or more servers for deployment. Before you can use any \
88
+ of the Capistrano deployment tasks with your project, you will need to \
89
+ make sure all of your servers have been prepared with `cap deploy:setup'. When \
90
+ you add a new server to your cluster, you can easily run the setup task \
91
+ on just that server by specifying the HOSTS environment variable:
92
+
93
+ $ cap HOSTS=new.server.com deploy:setup
94
+
95
+ It is safe to run this task on servers that have already been set up; it \
96
+ will not destroy any deployed revisions or data.
97
+ DESC
98
+ task :setup, :except => { :no_release => true } do
99
+ dirs = [deploy_to, releases_path, shared_path]
100
+ dirs += shared_children.map { |d| File.join(shared_path, d) }
101
+ tmp_dirs = tmp_children.map { |d| File.join(tmp_path, d) }
102
+ tmp_dirs += cache_children.map { |d| File.join(cache_path, d) }
103
+ run "#{try_sudo} mkdir -p #{(dirs + tmp_dirs).join(' ')} && #{try_sudo} chmod -R 777 #{tmp_path}" if (!user.empty?)
104
+ set :git_flag_quiet, "-q "
105
+ php.setup if (!php_lib_branch.empty?)
106
+ end
107
+
108
+ desc <<-DESC
109
+ Copies your project and updates the symlink. It does this in a \
110
+ transaction, so that if either `update_code' or `symlink' fail, all \
111
+ changes made to the remote servers will be rolled back, leaving your \
112
+ system in the same state it was in before `update' was invoked. Usually, \
113
+ you will want to call `deploy' instead of `update', but `update' can be \
114
+ handy if you want to deploy, but not immediately restart your application.
115
+ DESC
116
+ task :update do
117
+ transaction do
118
+ update_code
119
+ symlink
120
+ end
121
+ end
122
+
123
+ desc <<-DESC
124
+ Copies your project to the remote servers. This is the first stage \
125
+ of any deployment; moving your updated code and assets to the deployment \
126
+ servers. You will rarely call this task directly, however; instead, you \
127
+ should call the `deploy' task (to do a complete deploy) or the `update' \
128
+ task (if you want to perform the `restart' task separately).
129
+
130
+ You will need to make sure you set the :scm variable to the source \
131
+ control software you are using (it defaults to :subversion), and the \
132
+ :deploy_via variable to the strategy you want to use to deploy (it \
133
+ defaults to :checkout).
134
+ DESC
135
+ task :update_code, :except => { :no_release => true } do
136
+ on_rollback { run "rm -rf #{release_path}; true" }
137
+ strategy.deploy!
138
+ finalize_update
139
+ end
140
+
141
+ desc <<-DESC
142
+ [internal] Touches up the released code. This is called by update_code \
143
+ after the basic deploy finishes. It assumes a Rails project was deployed, \
144
+ so if you are deploying something else, you may want to override this \
145
+ task with your own environment's requirements.
146
+
147
+ This task will make the release group-writable (if the :group_writable \
148
+ variable is set to true, which is the default). It will then set up \
149
+ symlinks to the shared directory for the log, system, and tmp/pids \
150
+ directories, and will lastly touch all assets in public/images, \
151
+ public/stylesheets, and public/javascripts so that the times are \
152
+ consistent (so that asset timestamping works). This touch process \
153
+ is only carried out if the :normalize_asset_timestamps variable is \
154
+ set to true, which is the default.
155
+ DESC
156
+ task :finalize_update, :except => { :no_release => true } do
157
+ run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
158
+ end
159
+
160
+ desc <<-DESC
161
+ Updates the symlinks to the most recently deployed version. Capistrano works \
162
+ by putting each new release of your application in its own directory. When \
163
+ you deploy a new version, this task's job is to update the `current', \
164
+ `current/tmp', `current/webroot/system' symlinks to point at the new version. \
165
+
166
+ You will rarely need to call this task directly; instead, use the `deploy' \
167
+ task (which performs a complete deploy, including `restart') or the 'update' \
168
+ task (which does everything except `restart').
169
+ DESC
170
+ task :symlink, :except => { :no_release => true } do
171
+ on_rollback do
172
+ if previous_release
173
+ run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true"
174
+ else
175
+ logger.important "no previous release to rollback to, rollback of symlink skipped"
176
+ end
177
+ end
178
+ run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
179
+ end
180
+
181
+ desc <<-DESC
182
+ Copy files to the currently deployed version. This is useful for updating \
183
+ files piecemeal, such as when you need to quickly deploy only a single \
184
+ file. Some files, such as updated templates, images, or stylesheets, \
185
+ might not require a full deploy, and especially in emergency situations \
186
+ it can be handy to just push the updates to production, quickly.
187
+
188
+ To use this task, specify the files and directories you want to copy as a \
189
+ comma-delimited list in the FILES environment variable. All directories \
190
+ will be processed recursively, with all files being pushed to the \
191
+ deployment servers.
192
+
193
+ $ cap deploy:upload FILES=templates,controller.rb
194
+
195
+ Dir globs are also supported:
196
+
197
+ $ cap deploy:upload FILES='config/apache/*.conf'
198
+ DESC
199
+ task :upload, :except => { :no_release => true } do
200
+ files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
201
+ abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
202
+
203
+ files.each { |file| top.upload(file, File.join(current_path, file)) }
204
+ end
205
+
206
+ namespace :rollback do
207
+ desc <<-DESC
208
+ [internal] Points the current symlink at the previous revision.
209
+ This is called by the rollback sequence, and should rarely (if
210
+ ever) need to be called directly.
211
+ DESC
212
+ task :revision, :except => { :no_release => true } do
213
+ if previous_release
214
+ run "rm #{current_path}; ln -s #{previous_release} #{current_path};"
215
+ else
216
+ abort "could not rollback the code because there is no prior release"
217
+ end
218
+ end
219
+
220
+ desc <<-DESC
221
+ [internal] Removes the most recently deployed release.
222
+ This is called by the rollback sequence, and should rarely
223
+ (if ever) need to be called directly.
224
+ DESC
225
+ task :cleanup, :except => { :no_release => true } do
226
+ run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
227
+ end
228
+
229
+ desc <<-DESC
230
+ Rolls back to the previously deployed version. The `current' symlink will \
231
+ be updated to point at the previously deployed version, and then the \
232
+ current release will be removed from the servers.
233
+ DESC
234
+ task :code, :except => { :no_release => true } do
235
+ revision
236
+ cleanup
237
+ end
238
+
239
+ desc <<-DESC
240
+ Rolls back to a previous version and restarts. This is handy if you ever \
241
+ discover that you've deployed a lemon; `cap rollback' and you're right \
242
+ back where you were, on the previously deployed version.
243
+ DESC
244
+ task :default do
245
+ revision
246
+ cleanup
247
+ end
248
+ end
249
+
250
+ desc <<-DESC
251
+ Clean up old releases. By default, the last 5 releases are kept on each \
252
+ server (though you can change this with the keep_releases variable). All \
253
+ other deployed revisions are removed from the servers. By default, this \
254
+ will use sudo to clean up the old releases, but if sudo is not available \
255
+ for your environment, set the :use_sudo variable to false instead.
256
+ DESC
257
+ task :cleanup, :except => { :no_release => true } do
258
+ count = fetch(:keep_releases, 5).to_i
259
+ if count >= releases.length
260
+ logger.important "no old releases to clean up"
261
+ else
262
+ logger.info "keeping #{count} of #{releases.length} deployed releases"
263
+
264
+ directories = (releases - releases.last(count)).map { |release|
265
+ File.join(releases_path, release) }.join(" ")
266
+
267
+ try_sudo "rm -rf #{directories}"
268
+ end
269
+ end
270
+
271
+ desc <<-DESC
272
+ Test deployment dependencies. Checks things like directory permissions, \
273
+ necessary utilities, and so forth, reporting on the things that appear to \
274
+ be incorrect or missing. This is good for making sure a deploy has a \
275
+ chance of working before you actually run `cap deploy'.
276
+
277
+ You can define your own dependencies, as well, using the `depend' method:
278
+
279
+ depend :remote, :gem, "tzinfo", ">=0.3.3"
280
+ depend :local, :command, "svn"
281
+ depend :remote, :directory, "/u/depot/files"
282
+ DESC
283
+ task :check, :except => { :no_release => true } do
284
+ dependencies = strategy.check!
285
+
286
+ other = fetch(:dependencies, {})
287
+ other.each do |location, types|
288
+ types.each do |type, calls|
289
+ if type == :gem
290
+ dependencies.send(location).command(fetch(:gem_command, "gem")).or("`gem' command could not be found. Try setting :gem_command")
291
+ end
292
+
293
+ calls.each do |args|
294
+ dependencies.send(location).send(type, *args)
295
+ end
296
+ end
297
+ end
298
+
299
+ if dependencies.pass?
300
+ puts "You appear to have all necessary dependencies installed"
301
+ else
302
+ puts "The following dependencies failed. Please check them and try again:"
303
+ dependencies.reject { |d| d.pass? }.each do |d|
304
+ puts "--> #{d.message}"
305
+ end
306
+ abort
307
+ end
308
+ end
309
+
310
+ desc <<-DESC
311
+ Deploys and starts a `cold' application. This is useful if you have never \
312
+ deployed your application before. It currently runs `deploy:setup` followed \
313
+ by `deploy:update`. \
314
+ (This is still an experimental feature, and is subject to change without \
315
+ notice!)
316
+ DESC
317
+ task :cold do
318
+ setup
319
+ update
320
+ end
321
+
322
+ namespace :pending do
323
+ desc <<-DESC
324
+ Displays the `diff' since your last deploy. This is useful if you want \
325
+ to examine what changes are about to be deployed. Note that this might \
326
+ not be supported on all SCM's.
327
+ DESC
328
+ task :diff, :except => { :no_release => true } do
329
+ system(source.local.diff(current_revision))
330
+ end
331
+
332
+ desc <<-DESC
333
+ Displays the commits since your last deploy. This is good for a summary \
334
+ of the changes that have occurred since the last deploy. Note that this \
335
+ might not be supported on all SCM's.
336
+ DESC
337
+ task :default, :except => { :no_release => true } do
338
+ from = source.next_revision(current_revision)
339
+ system(source.local.log(from))
340
+ end
341
+ end
342
+
343
+ namespace :web do
344
+ desc <<-DESC
345
+ Present a maintenance page to visitors. Disables your application's web \
346
+ interface by writing a "maintenance.html" file to each web server. The \
347
+ servers must be configured to detect the presence of this file, and if \
348
+ it is present, always display it instead of performing the request.
349
+
350
+ By default, the maintenance page will just say the site is down for \
351
+ "maintenance", and will be back "shortly", but you can customize the \
352
+ page by specifying the REASON and UNTIL environment variables:
353
+
354
+ $ cap deploy:web:disable \\
355
+ REASON="hardware upgrade" \\
356
+ UNTIL="12pm Central Time"
357
+
358
+ Further customization will require that you write your own task.
359
+ DESC
360
+ task :disable, :roles => :web, :except => { :no_release => true } do
361
+ require 'erb'
362
+ on_rollback { run "rm #{shared_path}/system/maintenance.html" }
363
+
364
+ warn <<-EOHTACCESS
365
+
366
+ # Please add something like this to your site's htaccess to redirect users to the maintenance page.
367
+ # More Info: http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
368
+
369
+ ErrorDocument 503 /system/maintenance.html
370
+ RewriteEngine On
371
+ RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
372
+ RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
373
+ RewriteCond %{SCRIPT_FILENAME} !maintenance.html
374
+ RewriteRule ^.*$ - [redirect=503,last]
375
+ EOHTACCESS
376
+
377
+ reason = ENV['REASON']
378
+ deadline = ENV['UNTIL']
379
+
380
+ template = File.read(File.join(File.dirname(__FILE__), "templates", "maintenance.rhtml"))
381
+ result = ERB.new(template).result(binding)
382
+
383
+ put(result, "#{shared_path}/system/maintenance.html", :mode => 0644, :via => :scp)
384
+ end
385
+
386
+ desc <<-DESC
387
+ Makes the application web-accessible again. Removes the \
388
+ "maintenance.html" page generated by deploy:web:disable, which (if your \
389
+ web servers are configured correctly) will make your application \
390
+ web-accessible again.
391
+ DESC
392
+ task :enable, :roles => :web, :except => { :no_release => true } do
393
+ run "rm #{shared_path}/system/maintenance.html"
394
+ end
395
+ end
396
+
397
+ desc <<-DESC
398
+ Quick server(s) reset. For now, it deletes all files/folders in :deploy_to \
399
+ (This is still an experimental feature, and is subject to change without \
400
+ notice!) \
401
+
402
+ Used only when first testing setup deploy recipes and want to quickly \
403
+ reset servers.
404
+ DESC
405
+ task :destroy do
406
+ set(:confirm) do
407
+ Capistrano::CLI.ui.ask "This will delete your project on all servers. Are you sure you wish to continue? [Y/n]"
408
+ end
409
+ run "#{try_sudo} rm -rf #{deploy_to}/*" if (confirm == "Y")
410
+ end
411
+
412
+ end
413
+
414
+ namespace :php do
415
+
416
+ desc <<-DESC
417
+ Prepares server for deployment of a PHP application. \
418
+
419
+ By default, it will create a shallow clone of the PHP source repository \
420
+ inside #{shared_path}/php and run deploy:php:update.
421
+
422
+ For more info about shallow clones: \
423
+ http://www.kernel.org/pub/software/scm/git/docs/git-clone.html \
424
+
425
+ Further customization will require that you write your own task.
426
+ DESC
427
+ desc "Prepares server for deployment of a PHP application"
428
+ task :setup do
429
+ run "cd #{php_lib_path} && git clone --depth 1 #{php_lib_repo} #{php_lib_dir}"
430
+ set :git_flag_quiet, "-q "
431
+ update
432
+ end
433
+ desc <<-DESC
434
+ Force PHP installation to checkout a new branch/tag. \
435
+
436
+ By default, it will checkout the :php_lib_branch you set in \
437
+ deploy.rb, but you can change that on runtime by specifying \
438
+ the BRANCH environment variable:
439
+
440
+ $ cap deploy:php:update \\
441
+ BRANCH="1.3.0-alpha"
442
+
443
+ Further customization will require that you write your own task.
444
+ DESC
445
+ task :update do
446
+ set :php_branch, ENV['BRANCH'] if ENV.has_key?('BRANCH')
447
+ stream "cd #{php_lib_path}/#{php_lib_dir} && git checkout #{git_flag_quiet} #{php_lib_branch}"
448
+ end
449
+
450
+ namespace :cache do
451
+ desc <<-DESC
452
+ Clears anything in the cache.
453
+
454
+ Recursively finds all files in :cache_path and runs `rm -f` on each. If a file \
455
+ is renamed/removed after it was found but before it removes it, no error \
456
+ will prompt (-ignore_readdir_race). If symlinks are found, they will not be followed
457
+
458
+ You will rarely need to call this task directly; instead, use the `deploy' \
459
+ task (which performs a complete deploy, including `php:cache:clear')
460
+ DESC
461
+ task :clear, :roles => :web, :except => { :no_release => true } do
462
+ run "#{try_sudo} find -P #{cache_path} -ignore_readdir_race -type f -name '*' -exec rm -f {} \\;"
463
+ end
464
+ end
465
+
466
+ namespace :logs do
467
+ desc <<-DESC
468
+ Clears PHP's logs
469
+
470
+ Recursively finds all files in :logs_path and runs `rm -f` on each. If a file \
471
+ is renamed/removed after it was found but before it removes it, no error \
472
+ will prompt (-ignore_readdir_race). If symlinks are found, they will not be followed
473
+
474
+ DESC
475
+ task :clear, :roles => :web, :except => { :no_release => true } do
476
+ run "#{try_sudo} find -P #{logs_path} -ignore_readdir_race -type f -name '*' -exec rm -f {} \\;"
477
+ end
478
+ desc <<-DESC
479
+ Streams the result of `tail -f` on all :logs_files \
480
+
481
+ By default, the files are `debug` and `error`. You can add your own \
482
+ in config/deploy.rb
483
+
484
+ set :logs_files %w(debug error my_log_file)
485
+
486
+ DESC
487
+ task :tail, :roles => :web, :except => { :no_release => true } do
488
+ files = logs_files.map { |d| File.join(logs_path, d) }
489
+ stream "#{try_sudo} tail -f #{files.join(' ')}"
490
+ end
491
+ end
492
+
493
+ end
494
+
495
+ end # Capistrano::Configuration.instance(:must_exist).load do
@@ -0,0 +1,52 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
8
+ <title>System down for maintenance</title>
9
+
10
+ <style type="text/css">
11
+ div.outer {
12
+ position: absolute;
13
+ left: 50%;
14
+ top: 50%;
15
+ width: 500px;
16
+ height: 300px;
17
+ margin-left: -260px;
18
+ margin-top: -150px;
19
+ }
20
+
21
+ .DialogBody {
22
+ margin: 0;
23
+ padding: 10px;
24
+ text-align: left;
25
+ border: 1px solid #ccc;
26
+ border-right: 1px solid #999;
27
+ border-bottom: 1px solid #999;
28
+ background-color: #fff;
29
+ }
30
+
31
+ body { background-color: #fff; }
32
+ </style>
33
+ </head>
34
+
35
+ <body>
36
+
37
+ <div class="outer">
38
+ <div class="DialogBody" style="text-align: center;">
39
+ <div style="text-align: center; width: 200px; margin: 0 auto;">
40
+ <p style="color: red; font-size: 16px; line-height: 20px;">
41
+ The system is down for <%= reason ? reason : "maintenance" %>
42
+ as of <%= Time.now.strftime("%H:%M %Z") %>.
43
+ </p>
44
+ <p style="color: #666;">
45
+ It'll be back <%= deadline ? deadline : "shortly" %>.
46
+ </p>
47
+ </div>
48
+ </div>
49
+ </div>
50
+
51
+ </body>
52
+ </html>
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capify-php
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Tass Skoudros
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-14 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 9
27
+ segments:
28
+ - 2
29
+ - 5
30
+ version: "2.5"
31
+ name: capistrano
32
+ prerelease: false
33
+ type: :runtime
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ hash: 23
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ name: bundler
48
+ prerelease: false
49
+ type: :development
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 7
58
+ segments:
59
+ - 1
60
+ - 6
61
+ - 4
62
+ version: 1.6.4
63
+ name: jeweler
64
+ prerelease: false
65
+ type: :development
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ name: rcov
78
+ prerelease: false
79
+ type: :development
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 9
88
+ segments:
89
+ - 2
90
+ - 5
91
+ version: "2.5"
92
+ name: capistrano
93
+ prerelease: false
94
+ type: :runtime
95
+ requirement: *id005
96
+ description: Deploy PHP applications using Capistrano.
97
+ email: tass@skystack.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.markdown
105
+ - README.rdoc
106
+ files:
107
+ - lib/capify-php.rb
108
+ - lib/templates/maintenance.rhtml
109
+ - LICENSE.txt
110
+ - README.markdown
111
+ - README.rdoc
112
+ homepage: https://github.com/skystack/capify-php
113
+ licenses: []
114
+
115
+ post_install_message:
116
+ rdoc_options: []
117
+
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ requirements: []
139
+
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.10
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: All the power of Capistrano for PHP.
145
+ test_files: []
146
+