SHARE
TWEET

Untitled

a guest Sep 18th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'capistrano3-puma'
  2.  
  3. set :stages, %w(production staging)
  4. set :default_stage, "staging"
  5.  
  6. # server '95.216.148.99', port: 22, roles: [:web, :app, :db], primary: true
  7.  
  8. set :repo_url,        'git@bitbucket.org:m1kh41l/mirpokera.git'
  9. set :application,     'mirpokera'
  10.  
  11. # set :user,            'deploy'
  12. # set :puma_threads,    [4, 16]
  13. # set :puma_workers,    0
  14.  
  15. # set :rvm_custom_path, '/usr/share/rvm'  # only needed if not detected
  16. # set :rvm_ruby_version, '2.1.1@mirpokera'
  17.  
  18. # Don't change these unless you know what you're doing
  19. set :pty,             true
  20. set :use_sudo,        false
  21. set :stage,           :production
  22. set :deploy_via,      :remote_cache
  23. # set :deploy_to,       "/root/projects/#{fetch(:application)}"
  24. # set :deploy_to,       "/home/#{fetch(:user)}/projects/#{fetch(:application)}"
  25. set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
  26. set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
  27. set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
  28. set :puma_access_log, "#{release_path}/log/puma.error.log"
  29. set :puma_error_log,  "#{release_path}/log/puma.access.log"
  30. # set :ssh_options,     { forward_agent: true, user: 'deploy', keys: %w(~/.ssh/id_rsa.pub) }
  31. set :puma_preload_app, true
  32. set :puma_worker_timeout, nil
  33. set :puma_init_active_record, true  # Change to false when not using ActiveRecord
  34.  
  35. set :current_release, "#{fetch(:deploy_to)}/current/"
  36.  
  37. ## Defaults:
  38. # set :scm,           :git
  39. # set :branch,        :staging
  40. # set :format,        :pretty
  41. # set :log_level,     :debug
  42. # set :keep_releases, 5
  43.  
  44. ## Linked Files & Directories (Default None):
  45. set :linked_files, %w{config/database.yml public/sitemap.xml public/robots.txt}
  46. set :linked_dirs,  %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/pdf}
  47.  
  48. namespace :puma do
  49.   desc 'Create Directories for Puma Pids and Socket'
  50.   task :make_dirs do
  51.     on roles(:app) do
  52.       execute "mkdir #{shared_path}/tmp/sockets -p"
  53.       execute "mkdir #{shared_path}/tmp/pids -p"
  54.     end
  55.   end
  56.  
  57.   before :start, :make_dirs
  58. end
  59.  
  60. namespace :deploy do
  61.   desc "Make sure local git is in sync with remote."
  62.   task :check_revision do
  63.     on roles(:app) do
  64.       unless `git rev-parse HEAD` == `git rev-parse origin/master`
  65.         puts "WARNING: HEAD is not the same as origin/master"
  66.         puts "Run `git push` to sync changes."
  67.         exit
  68.       end
  69.     end
  70.   end
  71.  
  72.   desc 'Initial Deploy'
  73.   task :initial do
  74.     on roles(:app) do
  75.       before 'deploy:restart', 'puma:start'
  76.       invoke 'deploy'
  77.     end
  78.   end
  79.  
  80.   desc 'Restart application'
  81.   task :restart do
  82.     on roles(:app), in: :sequence, wait: 5 do
  83.       invoke!("puma:restart")
  84.     end
  85.   end
  86.  
  87.   before :starting,     :check_revision
  88.   after  :finishing,    :compile_assets
  89.   after  :finishing,    :cleanup
  90.   after  :finishing,    :restart
  91.  
  92.   namespace :delayed_job do
  93.     task :start do
  94.       on roles(:app) do
  95.         run "cd /home/deploy/projects/mirpokera/current && RAILS_ENV=production bin/delayed_job start"
  96.       end
  97.     end
  98.  
  99.     task :restart do
  100.       on roles(:app) do
  101.         run "cd /home/deploy/projects/mirpokera/current && RAILS_ENV=production bin/delayed_job restart"
  102.       end
  103.     end
  104.  
  105.     task :stop do
  106.       on roles(:app) do
  107.         run "cd /home/deploy/projects/mirpokera/current && RAILS_ENV=production bin/delayed_job stop"
  108.       end
  109.     end
  110.  
  111.     task :status do
  112.       on roles(:app) do
  113.         run "cd /home/deploy/projects/mirpokera/current && RAILS_ENV=production bin/delayed_job status"
  114.       end
  115.     end
  116.   end
  117.  
  118.   namespace :scheduler do
  119.     desc "Start the scheduler"
  120.     task :start do
  121.       on roles(:app) do
  122.         run "cd /home/deploy/projects/mirpokera/current && RAILS_ENV=production bundle exec ruby bin/scheduler.rb start"
  123.       end
  124.     end
  125.  
  126.     desc "Stop the scheduler"
  127.     task :stop do
  128.       on roles(:app) do
  129.         run "cd /home/deploy/projects/mirpokera/current && RAILS_ENV=production bundle exec ruby bin/scheduler.rb stop"
  130.       end
  131.     end
  132.  
  133.     desc "Restart the scheduler"
  134.     task :restart do
  135.       on roles(:app) do
  136.         run "cd /home/deploy/projects/mirpokera/current && RAILS_ENV=production bundle exec ruby bin/scheduler.rb restart"
  137.       end
  138.     end
  139.  
  140.     desc "Status of scheduler"
  141.     task :status do
  142.       on roles(:app) do
  143.         run "cd /home/deploy/projects/mirpokera/current && ruby bin/scheduler.rb status"
  144.       end
  145.     end
  146.   end
  147.  
  148.   # after :deploy, "deploy:delayed_job:restart"
  149. end
  150.  
  151.  
  152.  
  153. # ps aux | grep puma    # Get puma pid
  154. # kill -s SIGUSR2 pid   # Restart puma
  155. # kill -s SIGTERM pid   # Stop puma
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top