Commit dbc71b08dac24b4bd923cc3e60c3b7174de3e300

Authored by renansoares
1 parent 909de786
Exists in master and in 1 other branch v2

change deploy method

Capfile
... ... @@ -17,9 +17,11 @@ require 'capistrano/deploy'
17 17 require 'capistrano/rvm'
18 18 # require 'capistrano/rbenv'
19 19 # require 'capistrano/chruby'
  20 +require 'capistrano/rails'
20 21 require 'capistrano/bundler'
21 22 require 'capistrano/rails/assets'
22 23 require 'capistrano/rails/migrations'
  24 +require 'capistrano/puma'
23 25  
24 26 # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
25 27 Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
... ...
Gemfile
... ... @@ -85,3 +85,5 @@ group :test do
85 85 gem 'launchy'
86 86 gem 'selenium-webdriver'
87 87 end
  88 +
  89 +gem 'puma'
... ...
Gemfile.lock
... ... @@ -270,6 +270,7 @@ GEM
270 270 pry-rescue (1.4.1)
271 271 interception (>= 0.5)
272 272 pry
  273 + puma (3.2.0)
273 274 quiet_assets (1.0.2)
274 275 railties (>= 3.1, < 5.0)
275 276 rack (1.5.2)
... ... @@ -459,6 +460,7 @@ DEPENDENCIES
459 460 pry-debugger
460 461 pry-rails
461 462 pry-rescue
  463 + puma
462 464 quiet_assets
463 465 rack-livereload
464 466 rails (= 4.1.1)
... ...
config/deploy.rb
... ... @@ -8,9 +8,21 @@ set :repo_url, &#39;git@git.lavid.ufpb.br:vlibras-web2.git&#39;
8 8 # Default branch is :master
9 9 ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
10 10  
  11 +set :puma_threads, [4, 16]
  12 +set :puma_workers, 0
  13 +
11 14 # Default deploy_to directory is /var/www/my_app
12   -set :deploy_to, '/srv/vlibras-web2/'
  15 +set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
13 16 set :deploy_via, :copy
  17 +set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
  18 +set :puma_state, "#{shared_path}/tmp/pids/puma.state"
  19 +set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
  20 +set :puma_access_log, "#{release_path}/log/puma.error.log"
  21 +set :puma_error_log, "#{release_path}/log/puma.access.log"
  22 +set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
  23 +set :puma_preload_app, true
  24 +set :puma_worker_timeout, nil
  25 +set :puma_init_active_record, true # Change to false when not using ActiveRecord
14 26  
15 27 set :rails_env, 'production'
16 28  
... ... @@ -40,24 +52,51 @@ set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public
40 52 # Default value for keep_releases is 5
41 53 set :keep_releases, 3
42 54  
  55 +namespace :puma do
  56 + desc 'Create Directories for Puma Pids and Socket'
  57 + task :make_dirs do
  58 + on roles(:app) do
  59 + execute "mkdir #{shared_path}/tmp/sockets -p"
  60 + execute "mkdir #{shared_path}/tmp/pids -p"
  61 + end
  62 + end
  63 +
  64 + before :start, :make_dirs
  65 +end
  66 +
43 67 namespace :deploy do
44   - desc 'Restart application'
45   - task :restart do
46   - on roles(:web), in: :sequence, wait: 5 do
  68 + desc "Make sure local git is in sync with remote."
  69 + task :check_revision do
  70 + on roles(:app) do
  71 + unless `git rev-parse HEAD` == `git rev-parse origin/master`
  72 + puts "WARNING: HEAD is not the same as origin/master"
  73 + puts "Run `git push` to sync changes."
  74 + exit
  75 + end
47 76 end
48 77 end
49 78  
50   - after :publishing, :restart
  79 + desc 'Initial Deploy'
  80 + task :initial do
  81 + on roles(:app) do
  82 + before 'deploy:restart', 'puma:start'
  83 + invoke 'deploy'
  84 + end
  85 + end
51 86  
52   - after :restart, :clear_cache do
53   - on roles(:web), in: :groups, limit: 3, wait: 10 do
54   - # Here we can do anything such as:
55   - #within release_path do
56   - #execute :rake, 'assets:clobber'
57   - #execute :rake, 'assets:precompile'
58   - # execute :rake, 'tmp:clear -e production'
59   - #end
  87 + desc 'Restart application'
  88 + task :restart do
  89 + on roles(:app), in: :sequence, wait: 5 do
  90 + invoke 'puma:restart'
60 91 end
61 92 end
62 93  
  94 + before :starting, :check_revision
  95 + after :finishing, :compile_assets
  96 + after :finishing, :cleanup
  97 + after :finishing, :restart
63 98 end
  99 +
  100 +# ps aux | grep puma # Get puma pid
  101 +# kill -s SIGUSR2 pid # Restart puma
  102 +# kill -s SIGTERM pid # Stop puma
... ...
config/nginx.conf 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +
  2 +upstream puma {
  3 + server unix:///home/deployer/apps/vlibras-web2/shared/tmp/sockets/appname-puma.sock;
  4 +}
  5 +
  6 +server {
  7 + listen 80 default_server deferred;
  8 + # server_name example.com;
  9 +
  10 + root /home/deployer/apps/vlibras-web2/current/public;
  11 + access_log /home/deployer/apps/vlibras-web2/current/log/nginx.access.log;
  12 + error_log /home/deployer/apps/vlibras-web2/current/log/nginx.error.log info;
  13 +
  14 + location ^~ /assets/ {
  15 + gzip_static on;
  16 + expires max;
  17 + add_header Cache-Control public;
  18 + }
  19 +
  20 + try_files $uri/index.html $uri @puma;
  21 + location @puma {
  22 + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  23 + proxy_set_header Host $http_host;
  24 + proxy_redirect off;
  25 +
  26 + proxy_pass http://puma;
  27 + }
  28 +
  29 + error_page 500 502 503 504 /500.html;
  30 + client_max_body_size 10M;
  31 + keepalive_timeout 10;
  32 +}
... ...