Guest User

Untitled

a guest
Sep 21st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. require 'bundler/capistrano'
  2.  
  3. server "xxxxxxxxxxxxx", :web, :app, :db, primary: true
  4.  
  5. set :application, "myapp"
  6. set :user, "deployer"
  7. set :deploy_to, "/home/#{user}/apps/#{application}"
  8. set :deploy_via, :remote_cache
  9. set :use_sudo, false
  10.  
  11.  
  12. set :scm, :git
  13. set :repository, "git@github.com:pedro/myapp.git"
  14. set :branch, "master"
  15.  
  16.  
  17. default_run_options[:pty] = true
  18. ssh_options[:forward_agent] = true
  19.  
  20.  
  21. set :rails_env, "production"
  22.  
  23. after "deploy", "deploy:cleanup" # keep only the last 5 releases
  24.  
  25. namespace :deploy do
  26. %w[start stop restart].each do |command|
  27. desc "#{command} unicorn server"
  28. task command, roles: :app, except: {no_release: true} do
  29. run "/etc/init.d/unicorn_#{application} #{command}"
  30. end
  31. end
  32.  
  33. task :setup_config, roles: :app do
  34. sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
  35. sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
  36. run "mkdir -p #{shared_path}/config"
  37. put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
  38. puts "Now edit the config files in #{shared_path}."
  39. end
  40. after "deploy:setup", "deploy:setup_config"
  41.  
  42. task :socialstream_config, roles: :app do
  43. puts " ##################### socialstream config ############################"
  44. run "cd #{release_path} && bundle update --trace RAILS_ENV=production"
  45. run "cd #{release_path} && bundle exec rake db:drop --trace RAILS_ENV=production"
  46. run "cd #{release_path} && bundle exec rake db:create --trace RAILS_ENV=production"
  47. run "cd #{release_path} && bundle exec rake social_stream:migrations:update --trace #RAILS_ENV=production"
  48. run "cd #{release_path} && bundle exec rake db:migrate --trace RAILS_ENV=production"
  49. run "cd #{release_path} && bundle exec rake workers:start --trace RAILS_ENV=production"
  50. puts " ##################### socialstream config ############################"
  51. end
  52. before "deploy:migrate","deploy:socialstream_config"
  53. task :sphinx_config, roles: :app do
  54. puts " ##################### sphinx ############################"
  55. run "cd #{release_path} && bundle exec rake ts:config --trace RAILS_ENV=production"
  56. run "cd #{release_path} && bundle exec rake ts:rebuild --trace RAILS_ENV=production"
  57. run "cd #{release_path} && bundle exec rake ts:in --trace RAILS_ENV=production"
  58. puts " ##################### sphinx ############################"
  59. end
  60. after "deploy:migrate","deploy:sphinx_config"
  61.  
  62. task :symlink_config, roles: :app do
  63. run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  64. end
  65. after "deploy:finalize_update", "deploy:symlink_config"
  66.  
  67. desc "Make sure local git is in sync with remote."
  68. task :check_revision, roles: :web do
  69. unless `git rev-parse HEAD` == `git rev-parse origin/master`
  70. puts "WARNING: HEAD is not the same as origin/master"
  71. puts "Run `git push` to sync changes."
  72. exit
  73. end
  74. end
  75. before "deploy", "deploy:check_revision"
  76. end
Add Comment
Please, Sign In to add comment