Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. # config valid only for current version of Capistrano
  2. lock '3.4.0'
  3.  
  4. set :application, 'rails-api'
  5. set :repo_url, 'git@github.com:chaione/rails-api.git'
  6. set :user, 'deploy'
  7.  
  8. # set :nginx_domains, 'localhost'
  9. # set :app_server_socket, "#{shared_path}/sockets/puma-#{fetch :application}.sock"
  10.  
  11. # Default branch is :master
  12. ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
  13.  
  14. set :nginx_sites_available_path, '/etc/nginx/sites-available'
  15. set :nginx_sites_enabled_path, '/etc/nginx/sites-enabled'
  16. # Default deploy_to directory is /var/www/my_app_name
  17. # set :deploy_to, '/var/www/my_app_name'
  18.  
  19. set :puma_threads, [4, 16]
  20. set :puma_workers, 0
  21.  
  22. # Don't change these unless you know what you're doing
  23. set :pty, true
  24. set :use_sudo, false
  25. set :stage, :production
  26. set :deploy_via, :remote_cache
  27. set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
  28. set :puma_user, fetch(:user)
  29. set :puma_rackup, -> { File.join(current_path, 'config.ru') }
  30. set :puma_state, "#{shared_path}/tmp/pids/puma.state"
  31. set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
  32. set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" # accept array for multi-bind
  33. set :puma_default_control_app, "unix://#{shared_path}/tmp/sockets/pumactl.sock"
  34. set :puma_conf, "#{shared_path}/puma.rb"
  35. set :puma_access_log, "#{shared_path}/log/puma_access.log"
  36. set :puma_error_log, "#{shared_path}/log/puma_error.log"
  37. set :puma_role, :app
  38. set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
  39. set :puma_threads, [0, 16]
  40. set :puma_workers, 0
  41. set :puma_worker_timeout, nil
  42. set :puma_init_active_record, false
  43. set :puma_preload_app, true
  44. set :nginx_use_ssl, false
  45.  
  46. namespace :puma do
  47. desc 'Create Directories for Puma Pids and Socket'
  48. task :make_dirs do
  49. on roles(:app) do
  50. execute "mkdir #{shared_path}/tmp/sockets -p"
  51. execute "mkdir #{shared_path}/tmp/pids -p"
  52. end
  53. end
  54.  
  55. desc 'Start puma workers'
  56. task :start do
  57. on roles(:app) do
  58. with rails_env: fetch(:env), rack_env: fetch(:env) do
  59. sudo "start #{fetch(:puma_init_name)}"
  60. end
  61. end
  62. end
  63.  
  64. desc 'Stop puma workers'
  65. task :stop do
  66. on roles(:app) do
  67. with rails_env: fetch(:env), rack_env: fetch(:env) do
  68. sudo "stop #{fetch(:puma_init_name)}"
  69. end
  70. end
  71. end
  72.  
  73. desc 'Phased-restart puma workers (if running), start it otherwise'
  74. task :smart_restart do
  75. on roles(:app) do
  76. within current_path do
  77. with rails_env: fetch(:env), rack_env: fetch(:env) do
  78. if test("[ -f #{fetch(:puma_pid_path)} ]") && test("kill -0 $( cat #{fetch(:puma_pid_path)} )")
  79. execute :bundle, :exec, :pumactl, '-P tmp/pids/puma.pid', 'phased-restart'
  80. else
  81. sudo "start #{fetch(:puma_init_name)}"
  82. end
  83. end
  84. end
  85. end
  86. end
  87. after 'deploy:published', 'puma:smart_restart'
  88.  
  89. desc 'Restart puma workers'
  90. task :restart do
  91. invoke 'puma:stop'
  92. invoke 'puma:start'
  93. end
  94.  
  95. before :start, :make_dirs
  96. end
  97.  
  98. namespace :deploy do
  99. desc 'Make sure local git is in sync with remote.'
  100. task :check_revision do
  101. on roles(:app) do
  102. unless `git rev-parse HEAD` == `git rev-parse origin/master`
  103. puts 'WARNING: HEAD is not the same as origin/master'
  104. puts 'Run `git push` to sync changes.'
  105. exit
  106. end
  107. end
  108. end
  109.  
  110. desc 'Initial Deploy'
  111. task :initial do
  112. on roles(:app) do
  113. before 'deploy:restart', 'puma:start'
  114. invoke 'deploy'
  115. end
  116. end
  117.  
  118. desc 'Restart application'
  119. task :restart do
  120. on roles(:app), in: :sequence, wait: 5 do
  121. invoke 'puma:restart'
  122. end
  123. end
  124.  
  125. # before :starting, :check_revision
  126. after :finishing, :compile_assets
  127. after :finishing, :cleanup
  128. after :finishing, :restart
  129. end
  130.  
  131. namespace :load do
  132. task :defaults do
  133. set :puma_init_name, "#{fetch(:application)}-web"
  134. set :puma_pid_path, "#{shared_path}/tmp/pids/puma.pid"
  135. end
  136. end
  137. # # Default value for :linked_files is []
  138. # set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/images')
  139. # set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
  140.  
  141. namespace :deploy do
  142. after :restart, :clear_cache do
  143. on roles(:web), in: :groups, limit: 3, wait: 10 do
  144. # Here we can do anything such as:
  145. # within release_path do
  146. # execute :rake, 'cache:clear'
  147. # end
  148. end
  149. end
  150. end
  151.  
  152. server '0.0.0.0', user: 'deploy', roles: %w(web app db), primary: true
  153.  
  154. set :unicorn_rack_env, -> { 'production' }
  155. set :rails_env, :production
  156. # set :enable_ssl, true
  157.  
  158. # Defines a role with one or multiple servers. The primary server in each
  159. # group is considered to be the first unless any hosts have the primary
  160. # property set. Specify the username and a domain or IP for the server.
  161. # Don't use `:all`, it's a meta role.
  162. # Global options
  163.  
  164. set :ssh_options,
  165. keys: %w(~/.ssh/id_rsa),
  166. forward_agent: false,
  167. auth_methods: %w(password publickey),
  168. password: 'YzwUTO6RSggVj16cf2X1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement