Module: Ec2onrails::CapistranoUtils
- Defined in:
- lib/ec2onrails/capistrano_utils.rb
Instance Method Summary collapse
-
#hostnames_for_role(role_sym, options = {}) ⇒ Object
return hostnames for the role named role_sym that has the specified options.
-
#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 NOTE: this only executes on the first server in the list.
- #run_init_script(script, arg) ⇒ Object
- #run_local(command) ⇒ Object
Instance Method Details
#hostnames_for_role(role_sym, options = {}) ⇒ Object
return hostnames for the role named role_sym that has the specified options
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ec2onrails/capistrano_utils.rb', line 18 def hostnames_for_role(role_sym, = {}) 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 .each_pair{|k,v| match = false if s.[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 NOTE: this only executes on the first server in the list. Don’t use this to execute a task that has a side-effect (i.e. something that needs to be run on all servers).
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ec2onrails/capistrano_utils.rb', line 37 def quiet_capture(command, ={}) output = "" invoke_command(command, .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 12 13 14 15 |
# File 'lib/ec2onrails/capistrano_utils.rb', line 8 def run_init_script(script, arg) # TODO only restart a service if it's already started. # Aside from being smarter and more efficient, This will make sure we # aren't starting a service that shouldn't be started for the current # roles (e.g. don't start nginx when we're not in the web role) # How? Maybe need another param with the process name? sudo "/etc/init.d/#{script} #{arg}" 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 |