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

后端 未结 6 633
情话喂你
情话喂你 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:17

    Not necessarily the best option, but I hacked the following together for this problem in our project:

    task :remote_cmd do
      cmd = fetch(:cmd)
    
      puts `#{current_path}/script/console << EOF\r\n#{cmd}\r\n EOF`
    end
    

    To use it, I just use:

    cap remote_cmd -s cmd="a = 1; b = 2; puts a+b"
    

    (note: If you use Rails 3, you will have to change script/console above to rails console, however this has not been tested since I don't use Rails 3 on our project yet)

提交回复
热议问题