Skip to content

Instantly share code, notes, and snippets.

@bonyiii
Created July 25, 2011 07:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bonyiii/1103689 to your computer and use it in GitHub Desktop.
Save bonyiii/1103689 to your computer and use it in GitHub Desktop.
capistrano recipe
# https://rvm.beginrescueend.com/integration/capistrano/
# sudo and scons must be installed even though i don't want to use sudo at all. And i don't change user.
# also for git clone to work i have to set up ssh key in .ssh
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
require "rvm/capistrano" # Load RVM's capistrano plugin.
set :rvm_ruby_string, 'ruby-1.9.2@rails31' # Or whatever env you want it to run in.
set :rvm_type, :user # Copy the exact line. I really mean :user here
#http://blog.josephholsten.com/2010/09/deploying-with-bundler-and-capistrano/
require 'bundler/capistrano'
set :application, "Application"
set :repository, "test@server:/var/user/home/application.git"
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :user, "user"
#set :password, ""
set :use_sudo, false
#set :deploy_via, :copy #itt adjuk meg a stratégiát
#set :copy_strategy, :export
role :web, "server" # Your HTTP server, Apache/etc
role :app, "server" # This may be the same as your `Web` server
role :db, "server", :primary => true # This is where Rails migrations will run
#http://blog.josephholsten.com/2010/09/deploying-with-bundler-and-capistrano/
task :staging do
set :bundle_without, [:test]
set :deploy_to, "/var/user/house_staging/"
end
task :production do
stream <<-CMD
echo RVM path: $rvm_path;
CMD
# These are the default but we set them just to have it rest assured.
set :bundle_flags, "--deployment --quiet"
set :bundle_without, [:test, :development]
set :deploy_to, "/var/user/house2/"
# This should be automatical
set :current_path, "/var/user/house2/current"
set :env, "prod"
set :rails_env, "production"
end
namespace :unicorn do
set :current_path, "/var/user/house2/current"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
desc "start unicorn"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} bundle exec unicorn_rails -c #{current_path}/config/unicorn-#{rails_env}.rb -E #{rails_env} -D"
end
desc "stop unicorn"
task :stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill `cat #{unicorn_pid}`"
end
desc "graceful stop unicorn"
task :graceful_stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
end
desc "reload unicorn"
task :reload, :roles => :app, :except => { :no_release => true } do
run "if [ -f #{unicorn_pid} ]; then #{try_sudo} kill -s USR2 `cat #{unicorn_pid}`; fi"
end
after "deploy:restart", "unicorn:reload"
end
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
after 'deploy:symlink', 'deploy:symlink_shared'
before 'bundle:install', 'deploy:set_bundler_env'
before 'deploy:migrate', 'deploy:generate_engines'
after 'deploy:migrate', 'deploy:seed'
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
task :symlink_shared do
#run "ln -nfs #{shared_path}/Gemfile #{current_path}/Gemfile"
#run "ln -nfs #{shared_path}/Gemfile.lock #{current_path}/Gemfile.lock"
run "ln -nfs #{shared_path}/config/database.yml #{current_path}/config/database.yml"
end
task :generate_engines do
run "cd #{current_path}; RAILS_ENV=production BUNDLE_GEMFILE=#{current_path}/Gemfile bundle exec rails generate application_role Role User Permission"
run "cd #{current_path}; RAILS_ENV=production BUNDLE_GEMFILE=#{current_path}/Gemfile bundle exec rails generate application_menu Menu"
run "cd #{current_path}; RAILS_ENV=production BUNDLE_GEMFILE=#{current_path}/Gemfile bundle exec rails generate application_house"
end
task :seed do
run "cd #{current_path}; RAILS_ENV=production BUNDLE_GEMFILE=#{current_path}/Gemfile bundle exec rake db:seed"
end
task :set_bundler_env do
#run "cp #{shared_path}/Gemfile.lock #{shared_path}/Gemfile.lock.bak"
#run "mv #{shared_path}/Gemfile.lock.bak #{current_path}/Gemfile.lock"
# http://www.cowboycoded.com/2010/08/10/using-2-sources-for-a-gem-in-different-environments-with-bundler/
#run "export MY_BUNDLE_ENV='production'"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment