Module: OS

Defined in:
lib/fluent/plugin/os.rb

Overview

Utility class to determine the underlying operating system.

Class Method Summary collapse

Class Method Details

.debian?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/fluent/plugin/os.rb', line 30

def self.debian?
  linux? and os_name_debian?
end

.linux?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/fluent/plugin/os.rb', line 22

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

.mac?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/fluent/plugin/os.rb', line 14

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

.os_name_debian?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fluent/plugin/os.rb', line 52

def self.os_name_debian?
  os_name = 'not_found'
  file_name = '/etc/os-release'
  if File.exists?(file_name)
    File.foreach(file_name).each do |line|
      if line.start_with?('ID=')
        os_name = line.split('=')[1].strip
      end
    end
  else
    logger.info('Unknown linux distribution detected')
  end
  os_name == 'debian' ? true : false
rescue StandardError => e
  log.error "Unable to detect ubuntu platform due to: #{e.message}"
  false
end

.os_name_ubuntu?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fluent/plugin/os.rb', line 34

def self.os_name_ubuntu?
  os_name = 'not_found'
  file_name = '/etc/os-release'
  if File.exists?(file_name)
    IO.foreach(file_name).each do |line|
      if line.start_with?('ID=')
        os_name = line.split('=')[1].strip
      end
    end
  else
    logger.info('Unknown linux distribution detected')
  end
  os_name == 'ubuntu' ? true : false
rescue StandardError => e
  log.error "Unable to detect ubuntu platform due to: #{e.message}"
  false
end

.ubuntu?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/fluent/plugin/os.rb', line 26

def self.ubuntu?
  linux? and os_name_ubuntu?
end

.unix?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/fluent/plugin/os.rb', line 18

def self.unix?
  !OS.windows?
end

.windows?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/fluent/plugin/os.rb', line 10

def self.windows?
  (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end