Module: ORS::Helpers
- Includes:
- CommandHelpers, ParseHelpers, PrepareHelpers
- Included in:
- Commands::Base
- Defined in:
- lib/ors/helpers.rb
Defined Under Namespace
Modules: CommandHelpers, ParseHelpers, PrepareHelpers
Instance Method Summary collapse
- #build_command(server, *commands_and_maybe_options) ⇒ Object
-
#execute_command(server, *command_array) ⇒ Object
options = => ?, :capture => ?, :quiet_ssh => ?.
- #execute_in_parallel(servers) ⇒ Object
- #fatal(message) ⇒ Object
- #info(message) ⇒ Object
Methods included from CommandHelpers
#bundle_install, #restart_server, #run_migrations, #setup_repo, #setup_ruby, #start_server, #stop_server, #update_code
Methods included from PrepareHelpers
#prepare_environment, #prepare_environment_with_rvm, #prepare_initial_environment
Methods included from ParseHelpers
Instance Method Details
#build_command(server, *commands_and_maybe_options) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/ors/helpers.rb', line 146 def build_command server, * return "" if .empty? if .last.is_a?(Hash) = .pop command_array = else command_array = = {} end commands = command_array.join " && " psuedo_tty = [:exec] ? '-t ' : '' quiet_ssh = [:quiet_ssh] ? '-q ' : '' if [:local] commands else if ORS.config[:use_gateway] %(ssh #{quiet_ssh}#{psuedo_tty}#{ORS.config[:gateway]} 'ssh #{quiet_ssh}#{psuedo_tty}#{ORS.config[:user]}@#{server} "#{commands}"') else %(ssh #{quiet_ssh}#{psuedo_tty}#{ORS.config[:user]}@#{server} "#{commands}") end end end |
#execute_command(server, *command_array) ⇒ Object
options = => ?, :capture => ?, :quiet_ssh => ?
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/ors/helpers.rb', line 121 def execute_command(server, *command_array) = {:exec => false, :capture => false, :quiet_ssh => false} .merge!(command_array.pop) if command_array.last.is_a?(Hash) [:local] = true if server.to_s == "localhost" command = build_command(server, command_array, ) if ORS.config[:pretending] info("[#{server}] #{command}") else if [:exec] exec command else results = `#{command}` if [:capture] return results else results.split("\n").each do |result| info "[#{server}] #{result.chomp}\n" end end end end end |
#execute_in_parallel(servers) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/ors/helpers.rb', line 172 def execute_in_parallel servers servers.map do |server| Thread.new(server) do |server| yield server end end.map {|thread| thread.join } end |
#fatal(message) ⇒ Object
184 185 186 187 |
# File 'lib/ors/helpers.rb', line 184 def fatal info exit 1 end |
#info(message) ⇒ Object
180 181 182 |
# File 'lib/ors/helpers.rb', line 180 def info STDOUT.puts end |