class Azuki::Command::Run

run one-off commands (console, rake)

Public Instance Methods

console() click to toggle source
run:console [COMMAND]

open a remote console session

if COMMAND is specified, run the command and exit

NOTE: For Cedar apps, use `azuki run console`

Examples:

$ azuki console
Ruby console for example.azukiapp.com
>>
# File lib/azuki/command/run.rb, line 93
def console
  puts "`azuki #{current_command}` has been removed. Please use: `azuki run` instead."
  puts "For more information, please see:"
  puts " * https://devcenter.azukiapp.com/articles/one-off-dynos"
  puts " * https://devcenter.azukiapp.com/articles/rails3#console"
  puts " * https://devcenter.azukiapp.com/articles/console-bamboo"
end
detached() click to toggle source
run:detached COMMAND

run a detached process, where output is sent to your logs

-t, --tail           # stream logs for the process

Example:

$ azuki run:detached ls
Running `ls` detached... up, run.1
Use `azuki logs -p run.1` to view the output.
# File lib/azuki/command/run.rb, line 37
def detached
  command = args.join(" ")
  error("Usage: azuki run COMMAND") if command.empty?
  opts = { :attach => false, :command => command }
  app_name = app
  process_data = action("Running `#{command}` detached", :success => "up") do
    process_data = api.post_ps(app_name, command, { :attach => false }).body
    status(process_data['process'])
    process_data
  end
  if options[:tail]
    opts = []
    opts << "tail=1"
    opts << "ps=#{process_data['process']}"
    log_displayer = ::Azuki::Helpers::LogDisplayer.new(azuki, app, opts)
    log_displayer.display_logs
  else
    display("Use `azuki logs -p #{process_data['process']}` to view the output.")
  end
end
index() click to toggle source
run COMMAND

run an attached process

Example:

$ azuki run bash
Running `bash` attached to terminal... up, run.1
~ $
# File lib/azuki/command/run.rb, line 19
def index
  command = args.join(" ")
  error("Usage: azuki run COMMAND") if command.empty?
  run_attached(command)
end
rake() click to toggle source
run:rake COMMAND

WARNING: `azuki run:rake` has been deprecated. Please use `azuki run rake` instead."

remotely execute a rake command

Example:

$ azuki run:rake -T
Running `rake -T` attached to terminal... up, run.1
(in /app)
rake test  # run tests
# File lib/azuki/command/run.rb, line 71
def rake
  deprecate("`azuki #{current_command}` has been deprecated. Please use `azuki run rake` instead.")
  command = "rake #{args.join(' ')}"
  run_attached(command)
end

Protected Instance Methods

console_history_add(app, cmd) click to toggle source
# File lib/azuki/command/run.rb, line 176
def console_history_add(app, cmd)
  Readline::HISTORY.push(cmd)
  File.open(console_history_file(app), "a") { |f| f.puts cmd + "\n" }
end
console_history_dir() click to toggle source
# File lib/azuki/command/run.rb, line 137
def console_history_dir
  FileUtils.mkdir_p(path = "#{home_directory}/.azuki/console_history")
  path
end
console_history_file(app) click to toggle source
# File lib/azuki/command/run.rb, line 157
def console_history_file(app)
  "#{console_history_dir}/#{app}"
end
console_history_read(app) click to toggle source
# File lib/azuki/command/run.rb, line 161
def console_history_read(app)
  history = File.read(console_history_file(app)).split("\n")
  if history.size > 50
    history = history[(history.size - 51),(history.size - 1)]
    File.open(console_history_file(app), "w") { |f| f.puts history.join("\n") }
  end
  history.each { |cmd| Readline::HISTORY.push(cmd) }
rescue Errno::ENOENT
rescue Exception => ex
  display "Error reading your console history: #{ex.message}"
  if confirm("Would you like to clear it? (y/N):")
    FileUtils.rm(console_history_file(app)) rescue nil
  end
end
console_session(app) click to toggle source
# File lib/azuki/command/run.rb, line 142
def console_session(app)
  azuki.console(app) do |console|
    console_history_read(app)

    display "Ruby console for #{app}.#{azuki.host}"
    while cmd = Readline.readline('>> ')
      unless cmd.nil? || cmd.strip.empty?
        console_history_add(app, cmd)
        break if cmd.downcase.strip == 'exit'
        display console.run(cmd)
      end
    end
  end
end
rendezvous_session(rendezvous_url, &on_connect) click to toggle source
# File lib/azuki/command/run.rb, line 114
def rendezvous_session(rendezvous_url, &on_connect)
  begin
    set_buffer(false)
    rendezvous = Azuki::Client::Rendezvous.new(
      :rendezvous_url => rendezvous_url,
      :connect_timeout => (ENV["AZUKI_CONNECT_TIMEOUT"] || 120).to_i,
      :activity_timeout => nil,
      :input => $stdin,
      :output => $stdout)
    rendezvous.on_connect(&on_connect)
    rendezvous.start
  rescue Timeout::Error
    error "\nTimeout awaiting process"
  rescue OpenSSL::SSL::SSLError
    error "Authentication error"
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET
    error "\nError connecting to process"
  rescue Interrupt
  ensure
    set_buffer(true)
  end
end
run_attached(command) click to toggle source
# File lib/azuki/command/run.rb, line 104
def run_attached(command)
  app_name = app
  process_data = action("Running `#{command}` attached to terminal", :success => "up") do
    process_data = api.post_ps(app_name, command, { :attach => true, :ps_env => get_terminal_environment }).body
    status(process_data["process"])
    process_data
  end
  rendezvous_session(process_data["rendezvous_url"])
end