namespace :passenger do desc 'Restart your Passenger application' task :restart do 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 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') end end 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 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 end end task :after_rvm_path_is_set do # This is very similar to code in capistrano-rvm. Ideally, there would be a way to hook into that code instead of duplicating it with only minor changes. passenger_rvm_prefix = "#{fetch(:rvm_path)}/bin/rvm #{fetch(:passenger_rvm_ruby_version)} do" [:passenger, :'passenger-config'].each do |command| SSHKit.config.command_map.prefix[command.to_sym].unshift(passenger_rvm_prefix) end end end namespace :rbenv do task :hook do set :rbenv_map_bins, fetch(:rbenv_map_bins) + [:passenger, :'passenger-config'] end end end namespace :load do task :defaults do set :passenger_roles, :app set :passenger_restart_runner, :sequence set :passenger_restart_wait, 5 set :passenger_restart_limit, 2 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' end if Rake.application.tasks.collect(&:to_s).include?("rbenv:map_bins") before :'rbenv:map_bins', :'passenger:rbenv:hook' end end end