Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # config valid only for current version of Capistrano
- lock '3.4.0'
- set :application, 'rails-api'
- set :repo_url, 'git@github.com:chaione/rails-api.git'
- set :user, 'deploy'
- # set :nginx_domains, 'localhost'
- # set :app_server_socket, "#{shared_path}/sockets/puma-#{fetch :application}.sock"
- # Default branch is :master
- ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
- set :nginx_sites_available_path, '/etc/nginx/sites-available'
- set :nginx_sites_enabled_path, '/etc/nginx/sites-enabled'
- # Default deploy_to directory is /var/www/my_app_name
- # set :deploy_to, '/var/www/my_app_name'
- set :puma_threads, [4, 16]
- set :puma_workers, 0
- # Don't change these unless you know what you're doing
- set :pty, true
- set :use_sudo, false
- set :stage, :production
- set :deploy_via, :remote_cache
- set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
- set :puma_user, fetch(:user)
- set :puma_rackup, -> { File.join(current_path, 'config.ru') }
- set :puma_state, "#{shared_path}/tmp/pids/puma.state"
- set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
- set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" # accept array for multi-bind
- set :puma_default_control_app, "unix://#{shared_path}/tmp/sockets/pumactl.sock"
- set :puma_conf, "#{shared_path}/puma.rb"
- set :puma_access_log, "#{shared_path}/log/puma_access.log"
- set :puma_error_log, "#{shared_path}/log/puma_error.log"
- set :puma_role, :app
- set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
- set :puma_threads, [0, 16]
- set :puma_workers, 0
- set :puma_worker_timeout, nil
- set :puma_init_active_record, false
- set :puma_preload_app, true
- set :nginx_use_ssl, false
- namespace :puma do
- desc 'Create Directories for Puma Pids and Socket'
- task :make_dirs do
- on roles(:app) do
- execute "mkdir #{shared_path}/tmp/sockets -p"
- execute "mkdir #{shared_path}/tmp/pids -p"
- end
- end
- desc 'Start puma workers'
- task :start do
- on roles(:app) do
- with rails_env: fetch(:env), rack_env: fetch(:env) do
- sudo "start #{fetch(:puma_init_name)}"
- end
- end
- end
- desc 'Stop puma workers'
- task :stop do
- on roles(:app) do
- with rails_env: fetch(:env), rack_env: fetch(:env) do
- sudo "stop #{fetch(:puma_init_name)}"
- end
- end
- end
- desc 'Phased-restart puma workers (if running), start it otherwise'
- task :smart_restart do
- on roles(:app) do
- within current_path do
- with rails_env: fetch(:env), rack_env: fetch(:env) do
- if test("[ -f #{fetch(:puma_pid_path)} ]") && test("kill -0 $( cat #{fetch(:puma_pid_path)} )")
- execute :bundle, :exec, :pumactl, '-P tmp/pids/puma.pid', 'phased-restart'
- else
- sudo "start #{fetch(:puma_init_name)}"
- end
- end
- end
- end
- end
- after 'deploy:published', 'puma:smart_restart'
- desc 'Restart puma workers'
- task :restart do
- invoke 'puma:stop'
- invoke 'puma:start'
- end
- before :start, :make_dirs
- end
- namespace :deploy do
- desc 'Make sure local git is in sync with remote.'
- task :check_revision do
- on roles(:app) do
- unless `git rev-parse HEAD` == `git rev-parse origin/master`
- puts 'WARNING: HEAD is not the same as origin/master'
- puts 'Run `git push` to sync changes.'
- exit
- end
- end
- end
- desc 'Initial Deploy'
- task :initial do
- on roles(:app) do
- before 'deploy:restart', 'puma:start'
- invoke 'deploy'
- end
- end
- desc 'Restart application'
- task :restart do
- on roles(:app), in: :sequence, wait: 5 do
- invoke 'puma:restart'
- end
- end
- # before :starting, :check_revision
- after :finishing, :compile_assets
- after :finishing, :cleanup
- after :finishing, :restart
- end
- namespace :load do
- task :defaults do
- set :puma_init_name, "#{fetch(:application)}-web"
- set :puma_pid_path, "#{shared_path}/tmp/pids/puma.pid"
- end
- end
- # # Default value for :linked_files is []
- # set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/images')
- # set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
- namespace :deploy do
- after :restart, :clear_cache do
- on roles(:web), in: :groups, limit: 3, wait: 10 do
- # Here we can do anything such as:
- # within release_path do
- # execute :rake, 'cache:clear'
- # end
- end
- end
- end
- server '0.0.0.0', user: 'deploy', roles: %w(web app db), primary: true
- set :unicorn_rack_env, -> { 'production' }
- set :rails_env, :production
- # set :enable_ssl, true
- # Defines a role with one or multiple servers. The primary server in each
- # group is considered to be the first unless any hosts have the primary
- # property set. Specify the username and a domain or IP for the server.
- # Don't use `:all`, it's a meta role.
- # Global options
- set :ssh_options,
- keys: %w(~/.ssh/id_rsa),
- forward_agent: false,
- auth_methods: %w(password publickey),
- password: 'YzwUTO6RSggVj16cf2X1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement