forked from jhulick/ch-sheets
/
ruby.capistrano.sheet
149 lines (147 loc) · 6.44 KB
/
ruby.capistrano.sheet
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
This work is licensed under the Creative Commons
Attribution-NonCommercial-NoDerivs 2.0 License. To
view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-nd/2.0/ukn
########## Shell Commands ##########
Installation:
$ gem install capistrano
Add your application to Capistrano (capistranize):
$ cap --apply-to /path/to/your/app YourApplicationName
# NOTE: Rake access to capistrano is deprecated in Capistrano 1.3.
# Use the 'cap' command instead.
Execute the setup task:
$ rake remote:exec ACTION=setup
Execute the cold_deploy task:
$ rake remote:exec ACTION=cold_deploy
Deploy your application:
$ rake deploy
Similar to deploy, but it runs the migrate task on the new release before updating the symlink:
$ rake remote:deploy_with_migrations
Rollback a release from production:
$ rake rollback
Execute the disable_web task:
$ rake remote_exec ACTION=disable_web
UNTIL=\"tomorrow morning\"
REASON=\"vital upgrade\"
Using the invoke task:
$ rake remote_exec ACTION=invoke
COMMAND=\"svn up /u/apps/flipper/current/app/views\"
ROLES=appn
########## Standard Tasks ##########
cleans up the releases directory, leaving the five most recent releases:
$ cap cleanup
used when deploying an application for the first time. Starts the applicatioxE2\x80\x99s
spinner (via the spinner task) and then does a normal deploy:
$ cap cold_deploy
updates all the code on your server (via update_code and symlink
tasks), then restarts the FastCGI listeners on the application servers (via
the restart task):
$ cap deploy
prints the difference between what was last deployed, and what is
currently in your repository:
$ cap diff_from_last_deploy
puts up a static maintenance page that is displayed to visitors:
$ cap disable_web
removes the maintenance page:
$ cap enable_web
allows you to send commands directly:
$ cap invoke
changes to the directory of your current release (as indicated by the
current symlink), and runs rake RAILS_ENV=production migrate:
$ cap migrate
restarts all FastCGI listeners for your application by calling the reaper
command without arguments. Only executed on :app servers
$ cap restart
rolls your application back to the previously deployed version
determines the previous release , updates the current symlink to point
to that, and then deletes the latest release
$ cap rollback
Creates and chmods the directory tree properly:
$ cap setup
inspect the existing tasks and display them to standard out in
alphabetical order, along with their descriptions:
$ cap show_tasks
starts the spinner process for your application:
$ cap spinner
updates the current symlink to the latest deployed version of the code
$ cap symlink
Checks out your source code, deletes the log and public/system
directories in your new release, symlinks log to
#{shared_path}/log, symlinks public/system to #{shared_path}/system:
$ cap update_coden
########## config/deploy.rb ##########
*Defining Tasks
task :hello_world do run \"echo Hello, $HOSTNAME\"
end
task :hello_world, :roles => [:db, :app] do puts \"calling hello_world...\" hello_world
end
*Transactions
task :cold_deploy do transaction do task_one_here task_two_here end task_three_not_in_transaction
end
*Capturing output with run
run \"sudo ls -la\" do |channel, stream, data| if data =~ /^Password:/ logger.info \"#{channel[:host]} asked for password\" channel.send_data \"mypass\" end
end
buffer = render(:template =>
<<EXAMPLE_TEMPLATE) This template will be rendered replacing variables <%= like_this_variable => with their values.
EXAMPLE_TEMPLATE
put buffer, \"path/to/save/file.txt\", :mode => 0755
* multi-stage
set :stages, %w(staging production testing) # [optional] defaults to [development, test, staging?, production].
set :default_stage, \"testing\" # [optional] if omitted, cap aborts if you don't specify in args
require 'capistrano/ext/multistage'
Stage-specific code in config/deploy/staging.rb and config/deploy/production.rb.
see: http://weblog.jamisbuck.org/2007/7/23/capistrano-multistage
*deploy.rb variables and their defaults
The name of your application.
:application (required)
The location of your code\xE2\x80\x99s scm repository
:repository (required)
The address of the server to use as a gateway.
:gateway nil
The name of the user to use when logging into the remote host(s).
:user current_user
The password to use for logging into the remote host(s).
:password password
The root of the directory tree on the remote host(s) that the
application should be deployed to
:deploy_to \xE2\x80\x9C/u/apps/#{application}\xE2\x80\x9D
The directory under deploy_to that should contain each deployed revision.
:version_dir releases
The name to use (relative to deploy_to) for the symlink that points at
the current release
:current_dir current
The name of the directory under deploy_to that will contain directories and files to be shared between all releases.
:shared_dir shared
This specifies the revision you want to check out on the remote machines.
:revision (latest)
The source control module to use.
Current supported are :subversion, :cvs, :darcs
:scm subversion
The location on the remote host of the source control executable.
:svn,:cvs,:darcs
The subversion operation to use when checking out code on the remote host.
Can be set to \xE2\x80\x9Cexport\xE2\x80\x9D
:checkout \"co\"
Hash of additional options passed to the SSH connection routine.
This lets you set (among other things) a non-standard port to connect on:
(ssh_options[:port] = 2345)
:ssh_options Hash.new
Whether or not tasks that can use sudo, ought to use sudo. In a shared environment, this is typically not desirable (or possible), and
in that case you should set this variable to false
:use_sudo true
Sets the path to sudo.
:sudo
variables are set via:
set :application, \"flipper\"n
########## Interactive Shell ########## (requires capistrano-1.2.0)
Shell is essentially a SSH interface to your
servers, so you can run standard commands such
as 'ls' or 'cp' as well as Capistrano-specific ones.
Start the interactive Capistrano shell
$ cap -v shell
Execute Capistrano tasks
cap> !deploy
cap> !update_code symlink
cap> !setup deploy
cap> on app2.foo.com !setup
cap> with app,db !setup deploy"