Class: Hive::Diagnostic::Ios::Uptime
- Inherits:
-
Hive::Diagnostic
- Object
- Hive::Diagnostic
- Hive::Diagnostic::Ios::Uptime
- Defined in:
- lib/hive/diagnostic/ios/uptime.rb
Instance Method Summary collapse
Instance Method Details
#diagnose(data = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hive/diagnostic/ios/uptime.rb', line 9 def diagnose(data={}) if config.has_key?(:reboot_timeout) if @last_boot_time # DeviceAPI iOS doesn't currently supply uptime. uptime = (Time.now - @last_boot_time).to_i if uptime < config[:reboot_timeout] data[:next_reboot_in] = {:value => "#{config[:reboot_timeout] - uptime}", :unit => "s"} self.pass("Time for next reboot: #{config[:reboot_timeout] - uptime}s", data) else self.fail("Reboot required", data) end else self.fail('No recorded last boot. Rebooting.', data) end else self.pass("Not configured for reboot", data) end end |
#repair(result) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hive/diagnostic/ios/uptime.rb', line 28 def repair(result) data = {} Hive.logger.debug('[iOS]') { "Rebooting #{self.device_api.serial}" } begin data[:last_rebooted] = {:value => Time.now} self.device_api.reboot sleep 10 returned = false 60.times do |i| sleep 5 Hive.logger.debug('[iOS]') { "Wait for #{self.device_api.serial} (#{i})" } break if (returned = DeviceAPI::IOS::IDevice.devices.keys.include? self.device_api.serial) end # If 'trusted?' is tested too quickly it may(?) break the trust # This can probably be reduced or removed completely sleep 60 if returned trusted = false 60.times do |i| sleep 5 Hive.logger.debug('[iOS]') { "Wait for #{self.device_api.serial} to be trusted (#{i})" } break if (trusted = self.device_api.trusted?) end if trusted self.pass("Rebooted", data) else self.fail("Failed to trust after reboot", data) end else self.fail("Failed to reboot", data) end @last_boot_time = Time.now rescue => e Hive.logger.error('[iOS]') { "Caught exception #{e} while rebooting #{self.device_api.serial}" } end diagnose(data) end |