public
Created

  • Download Gist
deploy.rb
Ruby
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
set :stages, %w(staging production)
set :default_stage, 'staging'
require 'capistrano/ext/multistage'
 
set :application, "support"
set :scm, "git"
#default_run_options[:pty] = true
#set :ssh_options, { :forward_agent => true }
set :user, "deployer"
 
server "ruckweb2.securesites.net", :app, :web, :db, :primary => true
 
set :deploy_via, :remote_cache
 
#set :deploy_to, "/home/www_ftp/www/support.ruckuswireless.com"
 
set :rails_env, :production
 
set :db_username, "support_prod"
set :db_password, lambda { Capistrano::CLI.password_prompt('DB Password: ') }
set :db_name, 'support_stage'
 
# =============================================================================
# TASKS
# =============================================================================
# Define tasks that run on all (or only some) of the machines. You can specify
# a role (or set of roles) that each task should be executed on. You can also
# narrow the set of servers to a subset of a role by specifying options, which
# must match the options given for the servers to select (like :primary => true)
 
before("deploy:cleanup") { set :use_sudo, false }
after 'deploy:restart', 'deploy:kickstart'
after 'deploy:setup', :setup_database_config
after 'deploy:update_code', :link_shared_items
before 'deploy:migrate', :backup
 
desc "set the user to a sudo allowed user"
task :use_ruckweb2 do
set :user, "ruckweb2"
end
 
 
desc "Set up the expected application directory structure on all boxes"
task :setup, :except => { :no_release => true } do
send(run_method, "mkdir -p -m 775 #{releases_path} #{shared_path}/system")
send(run_method, "mkdir -p -m 777 #{shared_path}/log")
send(run_method, "mkdir -p -m 777 #{shared_path}/pids")
end
 
desc "Link in the production database.yml, mongrel cluster, and acts_as_attachment directories"
task :link_shared_items do
run <<-EOF
ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml
&& ln -nfs #{shared_path}/config/initializers/local_settings.rb #{release_path}/config/initializers/local_settings.rb
&& ln -nfs #{shared_path}/assets #{release_path}/public/assets
&& ln -nfs #{shared_path}/filestore #{release_path}/filestore
&& ln -nfs #{shared_path}/zftraining_teaser #{release_path}/public/zftraining_teaser
EOF
end
 
desc "Create database.yml in shared/config"
task :setup_database_config do
 
database_configuration = render :template => <<-EOF
login: &login
adapter: mysql
host: localhost
username: <%= db_username %>
password: <%= db_password %>
 
production:
database: <%= db_name %>
<<: *login
EOF
 
send(run_method, "mkdir -p -m 770 #{shared_path}/config #{shared_path}/filestore #{shared_path}/product_images")
put database_configuration, "#{shared_path}/config/database.yml"
end
 
desc "Backup the remote production database"
task :backup, :roles => :db, :only => { :primary => true } do
filename = "#{application}.dump.#{Time.now.to_i}.sql.bz2"
file = "/tmp/#{filename}"
on_rollback { run "rm -rf #{file}" }
db = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), 'database.yml'))).result)['production']
run "mysqldump -u #{db['username']} --password=#{db['password']} -h #{db['host']} #{db['database']} --ignore-table=#{db['database']}.sessions | bzip2 -c > #{file}" do |ch, stream, data|
puts data
end
backupdir = "#{File.dirname(__FILE__)}/../backups/"
Dir.mkdir backupdir unless File.exist? backupdir
get file, "backups/#{filename}"
run "rm -rf #{file}"
end
 
task :tail_log, :roles => :app do
stream "tail -f #{shared_path}/log/production.log"
end
 
namespace :deploy do
 
namespace :web do
 
desc "Serve up a custom maintenance page."
task :disable, :roles => :web do
require 'erb'
on_rollback { run "rm #{shared_path}/system/maintenance.html" }
template = File.read("app/views/layouts/maintenance.html.erb")
page = ERB.new(template).result(binding)
put page, "#{shared_path}/system/maintenance.html",
:mode => 0644
end
end
 
task :start, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
 
task :stop, :roles => :app do
# Do nothing.
end
 
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
 
desc "Perform a request to the website. after restart filter"
task :kickstart, :roles => :app do
run "curl -Is http://#{domain} > /dev/null"
end
 
end
 
 
Dir[File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'hoptoad_notifier-*')].each do |vendored_notifier|
$: << File.join(vendored_notifier, 'lib')
end
 
require 'hoptoad_notifier/capistrano'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.