Module: Ec2onrails::CapistranoUtils

Defined in:
lib/ec2onrails/capistrano_utils.rb

Instance Method Summary collapse

Instance Method Details

#hostnames_for_role(role_sym, options = {}) ⇒ Object

return hostnames for the role named role_sym that has the specified options



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ec2onrails/capistrano_utils.rb', line 14

def hostnames_for_role(role_sym, options = {})
  role = roles[role_sym]
  unless role
    return []
  end
  # make sure we match the server with all the passed in options, BUT the server can
  # have additional options defined.  e.g.: :primary => true and :ebs_vol_id => 'vol-1234abcd'
  # but we want to select the server where :primary => true
  role.select{|s| 
    match = true
    options.each_pair{|k,v| match = false if s.options[k] != v}
  }.collect{|s| s.host}
end

#quiet_capture(command, options = {}) ⇒ Object

Like the capture method, but does not print out error stream and swallows an exception if the process’s exit code != 0



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ec2onrails/capistrano_utils.rb', line 30

def quiet_capture(command, options={})
  output = ""
  invoke_command(command, options.merge(:once => true)) do |ch, stream, data|
    case stream
    when :out then output << data
    # when :err then warn "[err :: #{ch[:server]}] #{data}"
    end
  end
ensure
  return (output || '').strip
end

#run_init_script(script, arg) ⇒ Object



8
9
10
11
# File 'lib/ec2onrails/capistrano_utils.rb', line 8

def run_init_script(script, arg)
  # since init scripts might have the execute bit unset by the set_roles script we need to check
  sudo "sh -c 'if [ -x /etc/init.d/#{script} ] ; then /etc/init.d/#{script} #{arg}; fi'"
end

#run_local(command) ⇒ Object



3
4
5
6
# File 'lib/ec2onrails/capistrano_utils.rb', line 3

def run_local(command)
  result = system command
  raise("error: #{$?}") unless result
end