Skip to content

Commit 0c03c63

Browse files
author
rabble
committed
add stage task
add cap ssh git-svn-id: https://svn.radicaldesigns.org/voterguides/trunk@680 75c0e4a9-b6e4-0310-a6ec-d70c6baf2916
1 parent 213647b commit 0c03c63

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

cap_ssh_ports.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module Capistrano
2+
# A helper class for dealing with SSH connections.
3+
class SSH
4+
def self.connect(server, config, port=22, &block)
5+
methods = [ %w(publickey hostbased), %w(password keyboard-interactive) ]
6+
password_value = nil
7+
8+
begin
9+
ssh_options = { :username => config.user,
10+
:password => password_value,
11+
:port => port,
12+
:auth_methods => methods.shift }.merge(config.ssh_options)
13+
14+
# This regex is used for its byproducts, the $1-9 match vars.
15+
# This regex will always match the ssh hostname and if there
16+
# is a username or port they will be matched as well. This
17+
# allows us to set the username and ssh port right in the
18+
# role string: "[email protected]:8088"
19+
# This remains fully backwards compatible and can still be
20+
# intermixed with the old way of doing things. usernames
21+
# and ports will be used from the role string if present
22+
# but they will fall back to the regular defaults when not
23+
# present.
24+
server =~ /^(?:(\w+)@|)(.*?)(?::(\d+)|)$/
25+
ssh_options[:username] = $1 if $1
26+
ssh_options[:port] = $3 if $3
27+
28+
Net::SSH.start($2,ssh_options,&block)
29+
rescue Net::SSH::AuthenticationFailed
30+
raise if methods.empty?
31+
password_value = config.password
32+
retry
33+
end
34+
end
35+
end
36+
37+
end
38+

config/deploy.rb

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
role :web, "[email protected]:8050"
3232
role :app, "[email protected]:8050"
33-
role :app, "[email protected]:8051", :no_release => true, :no_symlink => true
33+
role :app, "[email protected]:8051", :no_release => true, :no_symlink => true
3434
role :db, "[email protected]:8050", :primary => true
3535

3636
# =============================================================================
@@ -109,3 +109,44 @@
109109
sudo "chmod 755 #{release_path}/public/themes/default.liquid"
110110
sudo "ln -nfs #{shared_path}/public/attachments #{release_path}/public/attachments"
111111
end
112+
113+
role :staging, '[email protected]'
114+
task :stage, :roles => :staging do
115+
#UPDATE CODE
116+
on_rollback { delete release_path, :recursive => true }
117+
118+
source.checkout(self)
119+
120+
run <<-CMD
121+
rm -rf #{release_path}/log #{release_path}/public/system &&
122+
ln -nfs #{shared_path}/log #{release_path}/log &&
123+
ln -nfs #{shared_path}/system #{release_path}/public/system
124+
CMD
125+
126+
run <<-CMD
127+
test -d #{shared_path}/pids &&
128+
rm -rf #{release_path}/tmp/pids &&
129+
ln -nfs #{shared_path}/pids #{release_path}/tmp/pids; true
130+
CMD
131+
132+
# uncache the list of releases, so that the next time it is called it will
133+
# include the newly released path.
134+
@releases = nil
135+
136+
#AFTER UPDATE CODE
137+
run <<-CMD
138+
ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml
139+
CMD
140+
141+
#AFTER SYMLINK
142+
run "ln -nfs #{shared_path}/public/attachments #{current_path}/public/attachments"
143+
run "ln -nfs #{shared_path}/public/themes #{current_path}/public/themes"
144+
145+
#RESTART
146+
begin
147+
run "cd #{current_path} && mongrel_rails restart"
148+
rescue RuntimeError => e
149+
puts e
150+
puts "Probably not a big deal, so I'll just keep trucking..."
151+
end
152+
end

0 commit comments

Comments
 (0)