diff options
author | Jacob Helwig <jacob@puppetlabs.com> | 2010-11-29 01:08:57 -0800 |
---|---|---|
committer | Jacob Helwig <jacob@puppetlabs.com> | 2011-01-24 14:50:20 -0800 |
commit | af9134c2d8911ee8bdd68ba95c64d51429ed6e16 (patch) | |
tree | ea239e0c40a06e07ff69cd61a868fc08c53ad731 /lib | |
parent | cbbfe55a7f0508c09d3b58fa8b8b95654c78bc06 (diff) | |
download | facter-af9134c2d8911ee8bdd68ba95c64d51429ed6e16.tar.gz facter-af9134c2d8911ee8bdd68ba95c64d51429ed6e16.tar.xz facter-af9134c2d8911ee8bdd68ba95c64d51429ed6e16.zip |
(#5086) Try using kstat before falling back to 'who -b' to determine uptime.
'who -b' doesn't report the year of the last system boot on (at least)
Solaris 10, and OpenSolaris 2009.06. Try using 'kstat -p
unix:::boot_time', which reports as seconds since the epoch on these
systems before falling back to 'who -b'.
Reviewed-by: Paul Berry <paul@puppetlabs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facter/util/uptime.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb index 9a59d30..4e6a7b6 100644 --- a/lib/facter/util/uptime.rb +++ b/lib/facter/util/uptime.rb @@ -4,7 +4,7 @@ require 'time' # module Facter::Util::Uptime def self.get_uptime_seconds_unix - uptime_proc_uptime or uptime_sysctl or uptime_who_dash_b + uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_who_dash_b end def self.get_uptime_seconds_win @@ -30,6 +30,12 @@ module Facter::Util::Uptime end end + def self.uptime_kstat + if output = Facter::Util::Resolution.exec("#{uptime_kstat_cmd} 2>/dev/null") + compute_uptime(Time.at(output.chomp.split(/\s/).last.to_i)) + end + end + def self.uptime_who_dash_b if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null") compute_uptime(Time.parse(output)) @@ -48,6 +54,10 @@ module Facter::Util::Uptime 'sysctl -b kern.boottime' end + def self.uptime_kstat_cmd + 'kstat -p unix:::boot_time' + end + def self.uptime_who_cmd 'who -b' end |