- 安装gem
gem ‘capistrano’, ‘2.12.0’
gem ‘capistrano-rbenv’, ‘1.0.1’
bundle - capify .
会生成两个文件: Capfile , config/deploy.rb - cap deploy:setup 会建立必须的 文件夹 (眼疾手快 及时停止executing “if test -f /etc/debian_version; then echo debian; elif test -f /etc/redhat-release; then echo redhat; elif test -f /etc/system-release; then echo redhat; else echo unknown; fi;”)
- 到服务器上 shared目录下创建config 文件夹 里面创建secrets.yml database.yml. application.yml 文件并配置
- 执行bundle exec cap deploy
一个deploy.rb 部署多个服务器
1 | SERVER_TEST_32 = "10.103.23.32" |
注:deploy.rb examle:
role :db, server, :primary => true
role :db, server
set :deploy_to, “/opt/app/test.wondercv.com”
default_run_options[:pty] = true
#change to your username
set :user, SSH_USER
namespace :deploy do
task :start do
run “cd #{release_path} && bundle exec thin start -C config/thin.yml”
end
task :stop do
run “cd #{release_path} && bundle exec thin stop -C config/thin.yml”
end
task :restart, :roles => :app, :except => { :no_release => true } do
db_migrate
stop
sleep 2
start
end
task :db_migrate do
run “cd #{release_path} && bundle install”
run “cd #{release_path} && RAILS_ENV=test bundle exec rake db:migrate”
end
namespace :assets do
task :precompile do
#puts “======= should run precompile”
#command = “cd #{release_path} && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile “
#puts “== please run == \n #{command} \n == manually after deploy is done”
#run “bundle install”
#run “cd #{release_path} && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile “
end
end
end
desc “Copy database.yml to release_path”
task :cp_database_yml do
puts “=== executing my customized command: “
run “cp -r #{shared_path}/config/* #{release_path}/config/“
run “ln -s #{shared_path}/files #{release_path}/public/files”
puts “=== done (executing my customized command)”
end
before “deploy:assets:precompile”, :cp_database_yml
#after “deploy”, “deploy:restart”