diff --git a/Capfile b/Capfile index 335828c06..e47ebb4fd 100644 --- a/Capfile +++ b/Capfile @@ -13,7 +13,7 @@ require "whenever/capistrano" require "rvm1/capistrano3" require "capistrano/puma" -install_plugin Capistrano::Puma +install_plugin Capistrano::Puma, load_hooks: false #SCM: Git require "capistrano/scm/git" diff --git a/config/deploy.rb b/config/deploy.rb index c3ebf428b..7cd43e03f 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -45,8 +45,6 @@ set(:config_files, %w[ set :whenever_roles, -> { :app } namespace :deploy do - Rake::Task["puma:check"].clear_actions - after :updating, "rvm1:install:rvm" after :updating, "rvm1:install:ruby" after :updating, "install_bundler_gem" @@ -55,14 +53,13 @@ namespace :deploy do after "deploy:migrate", "add_new_settings" before :publishing, "smtp_ssl_and_delay_jobs_secrets" + after :publishing, "setup_puma" - after :publishing, "deploy:restart" - after :published, "delayed_job:restart" - after :published, "refresh_sitemap" + after :published, "deploy:restart" + before "deploy:restart", "puma:smart_restart" + before "deploy:restart", "delayed_job:restart" - before "deploy:restart", "setup_puma" - - after :finishing, "deploy:cleanup" + after :finished, "refresh_sitemap" desc "Deploys and runs the tasks needed to upgrade to a new release" task :upgrade do diff --git a/config/puma.rb b/config/puma/defaults.rb similarity index 89% rename from config/puma.rb rename to config/puma/defaults.rb index 2389e7907..4f2ad945e 100644 --- a/config/puma.rb +++ b/config/puma/defaults.rb @@ -1,10 +1,9 @@ #!/usr/bin/env puma -rails_root = File.expand_path("../..", __FILE__) +rails_root = File.expand_path("../../..", __FILE__) directory rails_root rackup "#{rails_root}/config.ru" -environment "production" tag "" @@ -13,12 +12,14 @@ state_path "#{rails_root}/tmp/pids/puma.state" stdout_redirect "#{rails_root}/log/puma_access.log", "#{rails_root}/log/puma_error.log", true bind "unix://#{rails_root}/tmp/sockets/puma.sock" +daemonize threads 0, 16 workers 2 preload_app! restart_command "bundle exec --keep-file-descriptors puma" +plugin :tmp_restart on_restart do puts "Refreshing Gemfile" diff --git a/config/puma/preproduction.rb b/config/puma/preproduction.rb index 662d717be..cb965689c 100644 --- a/config/puma/preproduction.rb +++ b/config/puma/preproduction.rb @@ -1,5 +1,5 @@ #!/usr/bin/env puma -_load_from File.expand_path("../../puma.rb", __FILE__) +_load_from File.expand_path("../defaults.rb", __FILE__) environment "preproduction" diff --git a/config/puma/production.rb b/config/puma/production.rb index 7b693ef07..69d5508e3 100644 --- a/config/puma/production.rb +++ b/config/puma/production.rb @@ -1,5 +1,5 @@ #!/usr/bin/env puma -_load_from File.expand_path("../../puma.rb", __FILE__) +_load_from File.expand_path("../defaults.rb", __FILE__) environment "production" diff --git a/config/puma/staging.rb b/config/puma/staging.rb index 1097290ea..7f0321680 100644 --- a/config/puma/staging.rb +++ b/config/puma/staging.rb @@ -1,5 +1,5 @@ #!/usr/bin/env puma -_load_from File.expand_path("../../puma.rb", __FILE__) +_load_from File.expand_path("../defaults.rb", __FILE__) environment "staging" diff --git a/config/schedule.rb b/config/schedule.rb index 353190e5a..0c70a3ec7 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -39,3 +39,9 @@ end every 1.day, at: "3:00 am", roles: [:cron] do rake "votes:reset_hot_score" end + +every :reboot do + command "cd #{@path} && bundle exec puma -C config/puma/#{@environment}.rb" + # Number of workers must be kept in sync with capistrano's delayed_job_workers + command "cd #{@path} && RAILS_ENV=#{@environment} bin/delayed_job -n 2 restart" +end