Sha256: 50a7859d7574c40885fdb512f1aec81eb3a20123748585a7afaf013dde6b5b9a

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

namespace :rails do
  desc "Open the rails console on each of the remote servers"
  task :console do
    console_roles = [roles(:worker), roles(:app)].find(&:any?)
    on console_roles, primary: true do |host, user|
      run_interactively "RAILS_ENV=#{rails_env} bundle exec rails console"
    end
  end

  desc "Open the rails dbconsole on each of the remote servers"
  task :dbconsole do
    on roles(:db), primary: true do |host|
      run_interactively "RAILS_ENV=#{rails_env} bundle exec rails dbconsole"
    end
  end

  desc "Open the rails log"
  task :log do
    on roles(:app), primary: true do |host, user|
      filename = ENV['LOG'] || rails_env
      run_interactively %Q{tail -f log/#{filename}.log | grep --line-buffered --invert "Delayed::Backend::ActiveRecord::Job Load"}
    end
  end

  desc "Open all rails log using multitail"
  task :allthelogs do
    commands = []
    roles(:app).each do |host|
      filename = ENV['LOG'] || rails_env
      port = host.port || 22
      commands << "ssh #{host.user}@#{host} -p #{port} \"tail -f #{deploy_to}/current/log/#{filename}.log\" | grep --line-buffered --invert \"Delayed::Backend::ActiveRecord::Job Load\""
    end

    command = "multitail"
    commands.each do |c|
      command += " -L '#{c}'"
    end

    puts command
    exec command
  end

  desc "Run a rake task"
  task :rake, :task_to_run do |_, parameters|
    task_to_run = parameters[:task_to_run]
    abort "Must supply task to run on remote server.\nUsage example: cap dev rails:rake[flipper:synchronize_features]" if task_to_run.nil?
    roles = [roles(:worker), roles(:app)].find(&:any?)
    on roles, primary: true do
      run_interactively "RAILS_ENV=#{rails_env} bundle exec rake #{task_to_run}"
    end
  end

  def run_interactively(command)
    port = host.port || 22
    puts "ssh #{host.user}@#{host} -p #{port} -t 'cd #{deploy_to}/current; #{command}'"
    exec "ssh #{host.user}@#{host} -p #{port} -t 'cd #{deploy_to}/current; #{command}'"
  end

  def rails_env
    fetch(:rails_env)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jefferies_tube-1.5.2 lib/jefferies_tube/capistrano/rails.rb
jefferies_tube-1.5 lib/jefferies_tube/capistrano/rails.rb