Class: OsCtld::SystemLimits

Inherits:
Object
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, Lockable, Singleton
Defined in:
lib/osctld/system_limits.rb

Overview

Configurator of system-level resource limits

Constant Summary collapse

FILE_MAX_PATH =
'/proc/sys/fs/file-max'.freeze
FILE_MAX_DEFAULT =
1024 * 1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Lockable

#exclusively, included, #inclusively, #init_lock, #lock, #unlock

Constructor Details

#initializeSystemLimits

Returns a new instance of SystemLimits.



23
24
25
26
27
28
# File 'lib/osctld/system_limits.rb', line 23

def initialize
  init_lock
  @values = {}

  ensure_nofile(FILE_MAX_DEFAULT)
end

Instance Attribute Details

#valuesObject (readonly, protected)

Returns the value of attribute values.



49
50
51
# File 'lib/osctld/system_limits.rb', line 49

def values
  @values
end

Instance Method Details

#ensure_nofile(v) ⇒ Object

Parameters:

  • v (Integer)


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/osctld/system_limits.rb', line 31

def ensure_nofile(v)
  exclusively do
    values['nofile'] ||= File.read(FILE_MAX_PATH).strip.to_i

    if values['nofile'] < v
      log(:info, "Setting #{FILE_MAX_PATH} to #{v}")
      File.write(FILE_MAX_PATH, v.to_s)
      values['nofile'] = v
    end
  end
end

#log_typeObject



43
44
45
# File 'lib/osctld/system_limits.rb', line 43

def log_type
  'system-limits'
end