Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A sample Capistrano deploy.rb file I use as a base for all my projects. It's a straightforward & doesn't add much custom functionality besides symlinking my database.yml into my project from a folder outside of my application (considered good security practice).
require 'bundler/capistrano'
# Include this if you want to be able to set up different deployment stages (i.e. beta, stage, etc.)
# require 'capistrano/ext/multistage'
set :application, "example.com"
set :user, "linuxusername"
default_run_options[:pty] = true
set :use_sudo, true
set :repository, "path to git repo"
set :scm, :git
set :branch, "master"
role :app, application
role :web, application
role :db, application, :primary => true
set :stages, ["staging", "production"]
set :default_stage, "production"
set :deploy_to, "/path/to/project/on/server"
set :deploy_via, :copy
# How many versions of your deployed code to keep
set :keep_releases, 5
# Setup Shared Folders that should be created inside the shared_path
directory_configuration = %w(db config system)
# It's good security practice to put your database.yml and other sensitive files in another folder on your server & symlink them in
desc "Symlink shared config files"
task :symlink_config_files do
run "#{ try_sudo } ln -s #{ deploy_to }/shared/config/database.yml #{ current_path }/config/database.yml"
end
%w[start stop restart].each do |command|
desc "#{command} Memcached"
task command, roles: :app do
run "service memcached #{command}"
end
end
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
after "deploy", "deploy:symlink_config_files"
after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"
#http://stackoverflow.com/questions/3740152/how-to-set-chmod-for-a-folder-and-all-of-its-subfolders-and-files-in-linux-ubunt
# https://gist.github.com/meskyanichi/157958
# http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.