Skip to content

Instantly share code, notes, and snippets.

@gmcintire
Created December 2, 2010 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmcintire/725585 to your computer and use it in GitHub Desktop.
Save gmcintire/725585 to your computer and use it in GitHub Desktop.
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment