반응형
1. config/deploy.rb에 linked_dirs에 bin이 없는지 확인한다. 없어야만 한다.
2. 아래 코드를 config/deploy.rb에 추가한다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :rails do | |
desc "Start a rails console, for now just with the primary server" | |
task :c do | |
on roles(:app), primary: true do |role| | |
rails_env = fetch(:rails_env) | |
execute_remote_command_with_input "#{bundle_cmd_with_rbenv} #{current_path}/bin/rails console #{rails_env}" | |
end | |
end | |
def execute_remote_command_with_input(command) | |
port = fetch(:port) || 22 | |
puts "opening a console on: #{host}...." | |
cmd = "ssh -l #{fetch(:deploy_user)} #{host} -p #{port} -t 'cd #{deploy_to}/current && #{command}'" | |
exec cmd | |
end | |
def bundle_cmd_with_rbenv | |
if fetch(:rbenv_ruby) | |
"RBENV_VERSION=#{fetch(:rbenv_ruby)} RBENV_ROOT=#{fetch(:rbenv_path)} #{File.join(fetch(:rbenv_path), '/bin/rbenv')} exec bundle exec" | |
else | |
"ruby " | |
end | |
end | |
end |
반응형