Skip to content

Instantly share code, notes, and snippets.

@ej2015
Forked from joost/deploy.rb
Created October 10, 2018 09:12
Show Gist options
  • Save ej2015/78a7ad5ef33e34e6712c1eb084bc34d7 to your computer and use it in GitHub Desktop.
Save ej2015/78a7ad5ef33e34e6712c1eb084bc34d7 to your computer and use it in GitHub Desktop.

Revisions

  1. Joost Hietbrink revised this gist Mar 4, 2014. 1 changed file with 20 additions and 9 deletions.
    29 changes: 20 additions & 9 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,38 @@
    # encoding: UTF-8

    # Place in config/deploy.rb

    # See: https://gist.github.com/joost/9343156
    # Adapted to work with rbenv
    namespace :rails do
    desc "Open the rails console on each of the remote servers"
    desc "Open the rails console on primary app server"
    task :console do
    on roles(:app) do |host| #does it for each host, bad.
    on roles(:app), primary: true do
    rails_env = fetch(:stage)
    execute_interactively "ruby #{current_path}/script/rails console #{rails_env}"
    execute_interactively "#{bundle_cmd} #{current_path}/script/rails console #{rails_env}"
    end
    end

    desc "Open the rails dbconsole on each of the remote servers"
    desc "Open the rails dbconsole on primary db server"
    task :dbconsole do
    on roles(:db) do |host| #does it for each host, bad.
    on roles(:db), primary: true do
    rails_env = fetch(:stage)
    execute_interactively "ruby #{current_path}/script/rails dbconsole #{rails_env}"
    execute_interactively "#{bundle_cmd} #{current_path}/script/rails dbconsole #{rails_env}"
    end
    end

    def execute_interactively(command)
    user = fetch(:user)
    port = fetch(:port) || 22
    exec "ssh -l #{user} #{host} -p #{port} -t 'cd #{deploy_to}/current && #{command}'"
    cmd = "ssh -l #{user} #{host} -p #{port} -t 'cd #{deploy_to}/current && #{command}'"
    info "Connecting to #{host}"
    exec cmd
    end

    def bundle_cmd
    if fetch(:rbenv_ruby)
    # FIXME: Is there a better way to do this? How does "execute :bundle" work?
    "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{File.join(fetch(:rbenv_path), '/bin/rbenv')} exec bundle exec"
    else
    "ruby "
    end
    end
    end
  2. @toobulkeh toobulkeh revised this gist Jan 2, 2014. 2 changed files with 27 additions and 11 deletions.
    27 changes: 27 additions & 0 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    # encoding: UTF-8

    # Place in config/deploy.rb

    namespace :rails do
    desc "Open the rails console on each of the remote servers"
    task :console do
    on roles(:app) do |host| #does it for each host, bad.
    rails_env = fetch(:stage)
    execute_interactively "ruby #{current_path}/script/rails console #{rails_env}"
    end
    end

    desc "Open the rails dbconsole on each of the remote servers"
    task :dbconsole do
    on roles(:db) do |host| #does it for each host, bad.
    rails_env = fetch(:stage)
    execute_interactively "ruby #{current_path}/script/rails dbconsole #{rails_env}"
    end
    end

    def execute_interactively(command)
    user = fetch(:user)
    port = fetch(:port) || 22
    exec "ssh -l #{user} #{host} -p #{port} -t 'cd #{deploy_to}/current && #{command}'"
    end
    end
    11 changes: 0 additions & 11 deletions rails.rb
    Original file line number Diff line number Diff line change
    @@ -1,11 +0,0 @@
    # encoding: UTF-8

    Capistrano::Configuration.instance(:must_exist).load do
    namespace :rails do
    desc "Open the rails console on one of the remote servers"
    task :console, :roles => :app do
    hostname = find_servers_for_task(current_task).first
    exec "ssh -l #{user} #{hostname} -t 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'"
    end
    end
    end
  3. @benedikt benedikt revised this gist Sep 19, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rails.rb
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    desc "Open the rails console on one of the remote servers"
    task :console, :roles => :app do
    hostname = find_servers_for_task(current_task).first
    exec "ssh -l #{user} #{hostname} 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'"
    exec "ssh -l #{user} #{hostname} -t 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'"
    end
    end
    end
  4. @benedikt benedikt created this gist Jul 30, 2011.
    11 changes: 11 additions & 0 deletions rails.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # encoding: UTF-8

    Capistrano::Configuration.instance(:must_exist).load do
    namespace :rails do
    desc "Open the rails console on one of the remote servers"
    task :console, :roles => :app do
    hostname = find_servers_for_task(current_task).first
    exec "ssh -l #{user} #{hostname} 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'"
    end
    end
    end