lib/capistrano/tasks/puma.cap in capistrano3-puma-0.2.2 vs lib/capistrano/tasks/puma.cap in capistrano3-puma-0.3.3

- old
+ new

@@ -1,13 +1,14 @@ namespace :load do task :defaults do set :puma_role, :app - set :puma_env, -> { fetch(:rack_env, fetch(:rails_env, 'production')) } + set :puma_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) } # Configure "min" to be the minimum number of threads to use to answer # requests and "max" the maximum. set :puma_threads, [0, 16] set :puma_workers, 0 + set :puma_rackup, -> { File.join(current_path, 'config.ru') } set :puma_state, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') } set :puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') } set :puma_bind, -> { File.join('unix://', shared_path, 'tmp', 'sockets', 'puma.sock') } set :puma_conf, -> { File.join(shared_path, 'puma.rb') } set :puma_access_log, -> { File.join(shared_path, 'log', 'puma_error.log') } @@ -33,31 +34,41 @@ desc 'Start puma' task :start do on roles (fetch(:puma_role)) do within current_path do with rack_env: fetch(:puma_env) do + execute :bundle, 'exec', :puma, "-C #{fetch(:puma_conf)}" end end end end - %w[halt stop status].each do |command| + %w[halt stop status].map do |command| desc "#{command} puma" task command do on roles (fetch(:puma_role)) do within current_path do with rack_env: fetch(:puma_env) do - execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} #{command}" + if test "[ -f #{fetch(:puma_pid)} ]" + if test "kill -0 $( cat #{fetch(:puma_pid)} )" + execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} #{command}" + else + # delete invalid pid file , process is not running. + execute :rm, fetch(:puma_pid) + end + else + #pid file not found, so puma is probably not running or it using another pidfile + warn 'Puma not running' + end end end end end end - - %w[phased-restart restart].each do |command| + %w[phased-restart restart].map do |command| desc "#{command} puma" task command do on roles (fetch(:puma_role)) do within current_path do with rack_env: fetch(:puma_env) do @@ -72,11 +83,10 @@ end end end end - task :check do on roles (fetch(:puma_role)) do |role| #Create puma.rb for new deployments unless test "[ -f #{fetch(:puma_conf)} ]" warn 'puma.rb NOT FOUND!' @@ -95,11 +105,24 @@ invoke 'puma:restart' end end after 'deploy:finished', 'puma:smart_restart' + def puma_workers fetch(:puma_workers) || 0 + end + + def puma_tag + if fetch(:puma_tag) + # Versions(puma) prior to 2.8.2 don't support tag option + if Gem.loaded_specs['puma'].version >= Gem::Version.new('2.8.2') + return "tag '#{fetch(:puma_tag)}'" + else + warn 'Version puma 2.8.2+ required for tag option: Tag not set' + end + return + end end def template_puma(from, to, role) [ "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",