Class: RemoteExecutor::CliApplication
- Inherits:
-
Object
- Object
- RemoteExecutor::CliApplication
- Defined in:
- lib/remote_executor/cli_application.rb
Overview
CLI Application a simple point of entry
Constant Summary collapse
- COMMAND_SEPARATOR =
";"
Class Method Summary collapse
- .execute_commands(server, user, commands, ssh_options = { :config=>true }) ⇒ Object
- .process_system(system, commands, threaded) ⇒ Object
- .run(systems_config, log, threaded, name, commands) ⇒ Object
Class Method Details
.execute_commands(server, user, commands, ssh_options = { :config=>true }) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/remote_executor/cli_application.rb', line 14 def self.execute_commands( server, user, commands, ={ :config=>true } ) Net::SSH.start( server, user, ) do |ssh| commands.split( COMMAND_SEPARATOR ).each do |command| MiniLogger.debug( "Executing command #{user}@#{server} '#{command}'") ssh.exec( "#{command}" ) end end end |
.process_system(system, commands, threaded) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/remote_executor/cli_application.rb', line 27 def self.process_system( system, commands, threaded ) if( threaded ) threads = [] system.hosts.each do |server| threads << Thread.new( server ) { |t| execute_commands( server, system.user, commands ) } end threads.each { |t| t.join } else system.hosts.each do |server| execute_commands( server, system.user, commands ) end end end |
.run(systems_config, log, threaded, name, commands) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/remote_executor/cli_application.rb', line 48 def self.run( systems_config, log, threaded, name, commands ) MiniLogger.configure( :log_channel=>log, :log_level=>::Logger::DEBUG ) process_system( Systems.new( systems_config ).find_by_name( name ), commands, threaded ) rescue SystemsFileError =>sfe MiniLogger.error( sfe. ) rescue SystemNotFound =>snf MiniLogger.error( snf. ) end |