diff --git a/Capfile b/Capfile index d93dbfd..b1afcf9 100644 --- a/Capfile +++ b/Capfile @@ -17,9 +17,11 @@ require 'capistrano/deploy' require 'capistrano/rvm' # require 'capistrano/rbenv' # require 'capistrano/chruby' +require 'capistrano/rails' require 'capistrano/bundler' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' +require 'capistrano/puma' # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } diff --git a/Gemfile b/Gemfile index b3b56db..7024ae2 100644 --- a/Gemfile +++ b/Gemfile @@ -85,3 +85,5 @@ group :test do gem 'launchy' gem 'selenium-webdriver' end + +gem 'puma' diff --git a/Gemfile.lock b/Gemfile.lock index 41e8e27..213ba3b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -270,6 +270,7 @@ GEM pry-rescue (1.4.1) interception (>= 0.5) pry + puma (3.2.0) quiet_assets (1.0.2) railties (>= 3.1, < 5.0) rack (1.5.2) @@ -459,6 +460,7 @@ DEPENDENCIES pry-debugger pry-rails pry-rescue + puma quiet_assets rack-livereload rails (= 4.1.1) diff --git a/config/deploy.rb b/config/deploy.rb index 65f382d..40040e5 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -8,9 +8,21 @@ set :repo_url, 'git@git.lavid.ufpb.br:vlibras-web2.git' # Default branch is :master ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call +set :puma_threads, [4, 16] +set :puma_workers, 0 + # Default deploy_to directory is /var/www/my_app -set :deploy_to, '/srv/vlibras-web2/' +set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}" set :deploy_via, :copy +set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock" +set :puma_state, "#{shared_path}/tmp/pids/puma.state" +set :puma_pid, "#{shared_path}/tmp/pids/puma.pid" +set :puma_access_log, "#{release_path}/log/puma.error.log" +set :puma_error_log, "#{release_path}/log/puma.access.log" +set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) } +set :puma_preload_app, true +set :puma_worker_timeout, nil +set :puma_init_active_record, true # Change to false when not using ActiveRecord set :rails_env, 'production' @@ -40,24 +52,51 @@ set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public # Default value for keep_releases is 5 set :keep_releases, 3 +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 + + before :start, :make_dirs +end + namespace :deploy do - desc 'Restart application' - task :restart do - on roles(:web), in: :sequence, wait: 5 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 - after :publishing, :restart + desc 'Initial Deploy' + task :initial do + on roles(:app) do + before 'deploy:restart', 'puma:start' + invoke 'deploy' + end + end - 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, 'assets:clobber' - #execute :rake, 'assets:precompile' - # execute :rake, 'tmp:clear -e production' - #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 + +# ps aux | grep puma # Get puma pid +# kill -s SIGUSR2 pid # Restart puma +# kill -s SIGTERM pid # Stop puma diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 0000000..169bbf3 --- /dev/null +++ b/config/nginx.conf @@ -0,0 +1,32 @@ + +upstream puma { + server unix:///home/deployer/apps/vlibras-web2/shared/tmp/sockets/appname-puma.sock; +} + +server { + listen 80 default_server deferred; + # server_name example.com; + + root /home/deployer/apps/vlibras-web2/current/public; + access_log /home/deployer/apps/vlibras-web2/current/log/nginx.access.log; + error_log /home/deployer/apps/vlibras-web2/current/log/nginx.error.log info; + + location ^~ /assets/ { + gzip_static on; + expires max; + add_header Cache-Control public; + } + + try_files $uri/index.html $uri @puma; + location @puma { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + + proxy_pass http://puma; + } + + error_page 500 502 503 504 /500.html; + client_max_body_size 10M; + keepalive_timeout 10; +} -- libgit2 0.21.2