Class: Adminix::System

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/adminix/system.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (Boolean)


20
21
22
# File 'lib/adminix/system.rb', line 20

def self.linux?
  self.unix? and not self.mac?
end

.mac? ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/adminix/system.rb', line 12

def self.mac?
  (/darwin/ =~ RUBY_PLATFORM) != nil
end

.rvm? ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/adminix/system.rb', line 24

def self.rvm?
  true
end

.unix? ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/adminix/system.rb', line 16

def self.unix?
  !self.windows?
end

.windows? ⇒ Boolean

Returns:

  • (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

#eval(cmd) ⇒ Object



48
49
50
# File 'lib/adminix/system.rb', line 48

def eval(cmd)
  `#{cmd}`
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

#sudo? ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/adminix/system.rb', line 52

def sudo?
  @username == 'root'
end