Class: Adminix::System
- Inherits:
-
Object
- Object
- Adminix::System
- Includes:
- Singleton
- Defined in:
- lib/adminix/system.rb
Instance Attribute Summary collapse
-
#adminix_bin ⇒ Object
readonly
Returns the value of attribute adminix_bin.
-
#home ⇒ Object
readonly
Returns the value of attribute home.
-
#memory_load ⇒ Object
readonly
Returns the value of attribute memory_load.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
-
#processor_load ⇒ Object
readonly
Returns the value of attribute processor_load.
-
#ruby_version ⇒ Object
readonly
Returns the value of attribute ruby_version.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #check_system_load ⇒ Object
- #eval(cmd) ⇒ Object
- #generate_daemon ⇒ Object
-
#initialize ⇒ System
constructor
A new instance of System.
- #log(message) ⇒ Object
- #sudo? ⇒ Boolean
Constructor Details
#initialize ⇒ System
Returns a new instance of System.
30 31 32 33 34 35 |
# File 'lib/adminix/system.rb', line 30 def initialize define_os parse_system_info define_adminix_bin check_system_load end |
Instance Attribute Details
#adminix_bin ⇒ Object (readonly)
Returns the value of attribute adminix_bin.
28 29 30 |
# File 'lib/adminix/system.rb', line 28 def adminix_bin @adminix_bin end |
#home ⇒ Object (readonly)
Returns the value of attribute home.
28 29 30 |
# File 'lib/adminix/system.rb', line 28 def home @home end |
#memory_load ⇒ Object (readonly)
Returns the value of attribute memory_load.
28 29 30 |
# File 'lib/adminix/system.rb', line 28 def memory_load @memory_load end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
28 29 30 |
# File 'lib/adminix/system.rb', line 28 def os @os end |
#processor_load ⇒ Object (readonly)
Returns the value of attribute processor_load.
28 29 30 |
# File 'lib/adminix/system.rb', line 28 def processor_load @processor_load end |
#ruby_version ⇒ Object (readonly)
Returns the value of attribute ruby_version.
28 29 30 |
# File 'lib/adminix/system.rb', line 28 def ruby_version @ruby_version end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
28 29 30 |
# File 'lib/adminix/system.rb', line 28 def username @username end |
Class Method Details
.linux? ⇒ Boolean
20 21 22 |
# File 'lib/adminix/system.rb', line 20 def self.linux? self.unix? and not self.mac? end |
.mac? ⇒ Boolean
12 13 14 |
# File 'lib/adminix/system.rb', line 12 def self.mac? (/darwin/ =~ RUBY_PLATFORM) != nil end |
.rvm? ⇒ Boolean
24 25 26 |
# File 'lib/adminix/system.rb', line 24 def self.rvm? true end |
.unix? ⇒ Boolean
16 17 18 |
# File 'lib/adminix/system.rb', line 16 def self.unix? !self.windows? end |
.windows? ⇒ Boolean
8 9 10 |
# File 'lib/adminix/system.rb', line 8 def self.windows? (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil end |
Instance Method Details
#check_system_load ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/adminix/system.rb', line 58 def check_system_load case @os when :mac @processor_load = `ps -A -o %cpu | awk '{s+=$1} END {print s "%"}'`.to_f @memory_load = 0.1 when :linux, :unix @processor_load = `grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'`.to_f @memory_load = `free | grep Mem | awk '{print $3/$2 * 100.0}'`.to_f end end |
#eval(cmd) ⇒ Object
48 49 50 51 52 |
# File 'lib/adminix/system.rb', line 48 def eval(cmd) `#{cmd}` rescue => e e.to_s end |
#generate_daemon ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/adminix/system.rb', line 37 def generate_daemon template = File.read("#{Adminix::root}/views/daemon_scripts/upstart.conf.erb") file_content = ERB.new(template).result(binding) file_path = `pwd`.split("\n")[0] + '/adminix.conf' File.delete(file_path) if File.exists?(file_path) File.open(file_path, 'w') { |file| file.write(file_content) } file_path end |
#log(message) ⇒ Object
69 70 71 |
# File 'lib/adminix/system.rb', line 69 def log() puts unless config.daemon end |
#sudo? ⇒ Boolean
54 55 56 |
# File 'lib/adminix/system.rb', line 54 def sudo? @username == 'root' end |