Sabzdish

config/deploy.rb

Aug 14th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.29 KB | None | 0 0
  1. # config valid only for Capistrano 3.1
  2. lock '3.2.1'
  3.  
  4. set :application, 'НАЗВАНИЕ_ПРИЛОЖЕНИЯ'
  5. application = 'НАЗВАНИЕ_ПРИЛОЖЕНИЯ'
  6. set :repo_url, 'ПУТЬ К РЕПОЗИТОРИЮ'
  7. #set :user, "deployer"
  8. set :rails_env, "production"
  9. set :bundle_flags, "--deployment"
  10.  
  11. # Default branch is :master
  12. # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
  13.  
  14. # Default deploy_to directory is /var/www/my_app
  15. # set :deploy_to, '/var/www/my_app'
  16.  
  17. # Default value for :scm is :git
  18. # set :scm, :git
  19.  
  20. # Default value for :format is :pretty
  21. # set :format, :pretty
  22.  
  23. # Default value for :log_level is :debug
  24. # set :log_level, :debug
  25.  
  26. # Default value for :pty is false
  27. set :pty, true
  28.  
  29. # Default value for :linked_files is []
  30. # set :linked_files, %w{config/database.yml}
  31.  
  32. # Default value for linked_dirs is []
  33. # set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
  34.  
  35. # Default value for default_env is {}
  36. # set :default_env, { path: "/opt/ruby/bin:$PATH" }
  37.  
  38. # Default value for keep_releases is 5
  39. # set :keep_releases, 5
  40.  
  41. set :deploy_to, "/home/deployer/apps/#{application}"
  42. #set :deploy_via, :remote_cache
  43.  
  44. set :scm, "git"
  45. set :branch, "master"
  46.  
  47. set :ssh_options, { forward_agent: true }
  48.  
  49. set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"
  50. set :unicorn_config, "#{shared_path}/config/unicorn.rb"
  51.  
  52. namespace :git do
  53.   desc 'Push changes to repository'
  54.   task :push do
  55.     ask(:message, "Commit message?")
  56.     run_locally do
  57.       execute "git add -A"
  58.       execute "git commit -m '#{fetch(:message)}'"
  59.       execute "git push"
  60.     end
  61.   end
  62. end
  63.  
  64. namespace :unicorn do
  65.   desc 'Stop Unicorn'
  66.   task :stop do
  67.     on roles(:app) do
  68.       if test("[ -f #{fetch(:unicorn_pid)} ]")
  69.         execute :kill, capture(:cat, fetch(:unicorn_pid))
  70.       end
  71.     end
  72.   end
  73.  
  74.   desc 'Start Unicorn'
  75.   task :start do
  76.     on roles(:app) do
  77.       within current_path do
  78.         with rails_env: fetch(:rails_env) do
  79.           execute :bundle, "exec unicorn -c #{fetch(:unicorn_config)} -D"
  80.         end
  81.       end
  82.     end
  83.   end
  84.  
  85.   desc 'Reload Unicorn without killing master process'
  86.   task :reload do
  87.     on roles(:app) do
  88.       if test("[ -f #{fetch(:unicorn_pid)} ]")
  89.         execute :kill, '-s USR2', capture(:cat, fetch(:unicorn_pid))
  90.       else
  91.         error 'Unicorn process not running'
  92.       end
  93.     end
  94.   end
  95.  
  96.   desc 'Restart Unicorn'
  97.   task :restart
  98.   before :restart, :stop
  99.   before :restart, :start
  100. end
  101.  
  102. namespace :deploy do
  103.   desc 'Setup Config'
  104.   task :setup_config do
  105.     on roles(:all) do
  106.       execute "mkdir -p #{shared_path}/config"
  107.       execute "mkdir -p #{shared_path}/pids"
  108.       upload!('shared/database.yml', "#{shared_path}/config/")
  109.       upload!('shared/nginx.conf', "#{shared_path}/config/")
  110.       upload!('shared/unicorn.rb', "#{shared_path}/config/")
  111.       sudo "ln -nfs #{shared_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
  112.       sudo "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  113.     end
  114.   end
  115.  
  116.   # before :starting, "git:push"
  117.   after :updating, "deploy:setup_config"
  118.   before :publishing, "unicorn:stop"
  119.   after :publishing, "unicorn:start"
  120.   after :finishing, "deploy:cleanup" # keep only the last 5 releases
  121. end
Advertisement
Add Comment
Please, Sign In to add comment