Skip to content

Instantly share code, notes, and snippets.

@apneadiving
Created October 31, 2011 17:19
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 apneadiving/1328055 to your computer and use it in GitHub Desktop.
Save apneadiving/1328055 to your computer and use it in GitHub Desktop.
basic capistrano script
require 'yaml'
CAP = YAML.load_file("./config/deploy.yml")
require "bundler/capistrano"
set :bundle_cmd, "/usr/local/rvm/gems/ree-1.8.7-2011.03/bin/bundle"
set :bundle_without, [:development, :test]
default_run_options[:pty] = true # Must be set for the password prompt from git to work
set :repository, CAP["repository"] # Your clone URL
set :branch, "master"
set :scm, "git"
set :scm_username, CAP["git_user"]
set :scm_passphrase, CAP["passphrase"] # The deploy user's password
set :user, CAP["server_user"] # The server's user for deploys
set :deploy_to, "/var/www/#{CAP["website"]}"
set :use_sudo, true
set :keep_releases, 5
server "#{CAP["website"]}", :app, :web, :db, :primary => true
before 'deploy','deploy:rights_admin_on'
before 'deploy:web:enable','deploy:rights_admin_on'
before 'deploy:web:disable','deploy:rights_admin_on'
after 'deploy' do
symlinks.create
db.migrate
run "#{try_sudo} a2enmod rewrite" #pour permettre caching
deploy.cleanup
deploy.rights_admin_off
end
after 'deploy:web:enable', 'deploy:rights_admin_off'
after 'deploy:web:disable', 'deploy:rights_admin_off'
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
passenger.restart
end
task :rights_admin_on do
run "#{try_sudo} chown -R capistrano.capistrano /var/www/#{CAP["website"]}"
end
task :rights_admin_off do
run "#{try_sudo} chown -R www-data.www-data /var/www/#{CAP["website"]}"
end
end
namespace :db do
desc "Migrate Production Database"
task :migrate do
puts "\n\n=== Migrating the Production Database! ===\n\n"
run "cd #{current_path}; /usr/local/rvm/bin/rake db:migrate RAILS_ENV=production"
end
desc "Populates the Production Database"
task :seed do
puts "\n\n=== Populating the Production Database! ===\n\n"
run "cd #{current_path}; /usr/local/rvm/bin/rake db:seed RAILS_ENV=production"
end
end
namespace :passenger do
desc "Restarts Passenger"
task :restart do
puts "\n\n=== Restarting Passenger! ===\n\n"
run "touch #{current_path}/tmp/restart.txt"
end
end
namespace :symlinks do
desc "Creates the symlinks"
task :create do
puts "\n\n=== Rebuilding symlinks ===\n\n"
run "ln -s #{shared_path}/database.yml #{release_path}/config/database.yml"
run "ln -s #{shared_path}/s3.yml #{release_path}/config/s3.yml"
run "ln -s #{shared_path}/payzen.yml #{release_path}/config/payzen.yml"
#run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
run "ln -nfs #{shared_path}/cache #{release_path}/cache"
run "ln -nfs #{shared_path}/log #{release_path}/log"
end
end
require 'hoptoad_notifier/capistrano'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment