lib/capistrano/tasks/passenger.cap in capistrano-passenger-0.0.5 vs lib/capistrano/tasks/passenger.cap in capistrano-passenger-0.1.0

- old
+ new

@@ -1,31 +1,45 @@ namespace :passenger do desc 'Restart your Passenger application' task :restart do + restart_with_touch = fetch(:passenger_restart_with_touch, nil) + if restart_with_touch.nil? && fetch(:sshkit_backend) == SSHKit::Backend::Printer + run_locally do + fatal "In a dry run, we cannot check the passenger version, and therefore can't guess which passenger restart method to use. Therefore, using --dry-run without setting `passenger_restart_with_touch` to either `true` or `false` is not supported." + end + exit + end on roles(fetch(:passenger_roles)), in: fetch(:passenger_restart_runner), wait: fetch(:passenger_restart_wait), limit: fetch(:passenger_restart_limit) do with fetch(:passenger_environment_variables) do - passenger_version = capture(:passenger, '-v').match(/\APhusion Passenger version (.*)$/)[1].to_i + within(release_path) do + if restart_with_touch.nil? + passenger_version = capture(:passenger, '-v').match(/\APhusion Passenger version (.*)$/)[1] + restart_with_touch = Gem::Version.new(passenger_version) < Gem::Version.new('4.0.33') + end - if passenger_version > 4 - restart_with_sudo = fetch(:passenger_restart_with_sudo) ? :sudo : nil - arguments = [restart_with_sudo, *fetch(:passenger_restart_command).split(" ").collect(&:to_sym), fetch(:passenger_restart_options)].compact - execute *arguments - else - execute :mkdir, '-p', release_path.join('tmp') - execute :touch, release_path.join('tmp/restart.txt') + if restart_with_touch + execute :mkdir, '-p', release_path.join('tmp') + execute :touch, release_path.join('tmp/restart.txt') + else + restart_with_sudo = fetch(:passenger_restart_with_sudo) ? :sudo : nil + arguments = SSHKit::Command.new(*[*fetch(:passenger_restart_command).split(" ").collect(&:to_sym), fetch(:passenger_restart_options)]).to_s + execute *[restart_with_sudo, arguments].compact + end end end end end + task :test_which_passenger do + on roles(fetch(:passenger_roles)) do + set(:passenger_in_path, test(:which, :passenger)) + end + end + namespace :rvm do - task :hook do - passenger_installed_via_rvm = false - on roles(fetch(:passenger_roles)) do - passenger_installed_via_rvm = !(test :which, :passenger) - end - if passenger_installed_via_rvm + task hook: :"passenger:test_which_passenger" do + unless fetch(:passenger_in_path) if fetch(:passenger_rvm_ruby_version) == fetch(:rvm_ruby_version) set :rvm_map_bins, fetch(:rvm_map_bins) + [:passenger, :'passenger-config'] else after :'rvm:hook', :'passenger:rvm:after_rvm_path_is_set' end @@ -40,17 +54,28 @@ end end end namespace :rbenv do + task hook: :"passenger:test_which_passenger" do + set :rbenv_map_bins, fetch(:rbenv_map_bins) + [:passenger, :'passenger-config'] unless fetch(:passenger_in_path) + end + end + + namespace :chruby do + task hook: :"passenger:test_which_passenger" do + set :chruby_map_bins, fetch(:chruby_map_bins) + [:passenger, :'passenger-config'] unless fetch(:passenger_in_path) + end + end + + namespace :bundler do task :hook do - set :rbenv_map_bins, fetch(:rbenv_map_bins) + [:passenger, :'passenger-config'] + set :bundle_bins, fetch(:bundle_bins) + [:passenger, :'passenger-config'] if fetch(:passenger_in_gemfile, false) end end end - namespace :load do task :defaults do set :passenger_roles, :app set :passenger_restart_runner, :sequence set :passenger_restart_wait, 5 @@ -58,13 +83,18 @@ set :passenger_restart_with_sudo, false set :passenger_environment_variables, {} set :passenger_restart_command, 'passenger-config restart-app' set :passenger_restart_options, -> { "#{deploy_to} --ignore-app-not-running" } set :passenger_rvm_ruby_version, ->{ fetch(:rvm_ruby_version) } - if Rake.application.tasks.collect(&:to_s).include?("rvm:hook") - before :'rvm:hook', :'passenger:rvm:hook' + _tasks = Rake.application.tasks.collect(&:to_s) + if _tasks.include?("bundler:map_bins") + before :'bundler:map_bins', :'passenger:bundler:hook' end - if Rake.application.tasks.collect(&:to_s).include?("rbenv:map_bins") + if _tasks.include?("rvm:hook") + before :'rvm:hook', :'passenger:rvm:hook' + elsif _tasks.include?("rbenv:map_bins") before :'rbenv:map_bins', :'passenger:rbenv:hook' + elsif _tasks.include?("chruby:map_bins") + before :'chruby:map_bins', :'passenger:chruby:hook' end end end