Is there a way to use capistrano (or similar) to remotely interact with rails console

后端 未结 6 634
情话喂你
情话喂你 2021-02-03 11:50

I\'m loving how capistrano has simplified my deployment workflow, but often times a pushed change will run into issues that I need to log into the server to troubleshoot via the

6条回答
  •  走了就别回头了
    2021-02-03 12:19

    The article http://errtheblog.com/posts/19-streaming-capistrano has a great solution for this. I just made a minor change so that it works in multiple server setup.

      desc "open remote console (only on the last machine from the :app roles)"
      task :console, :roles => :app do
        server = find_servers_for_task(current_task).last
        input = ''
    
        run "cd #{current_path} && ./script/console #{rails_env}", :hosts => server.host do |channel, stream, data|
          next if data.chomp == input.chomp || data.chomp == ''
          print data
          channel.send_data(input = $stdin.gets) if data =~ /^(>|\?)>/
        end
      end
    

    the terminal you get is not really amazing though. If someone have some improvement that would make CTRL-D and CTRL-H or arrows working, please post it.

提交回复
热议问题