Class: Haconiwa::SmallCgroup
- Inherits:
-
Object
- Object
- Haconiwa::SmallCgroup
- Defined in:
- lib/haconiwa/small_cgroup.rb
Class Attribute Summary collapse
-
.fs_root ⇒ Object
Returns the value of attribute fs_root.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Class Method Summary collapse
Instance Method Summary collapse
- #activate(dir) ⇒ Object
- #activated?(dir) ⇒ Boolean
-
#initialize(name: "haconiwa-#{$$}", pid: $$) ⇒ SmallCgroup
constructor
A new instance of SmallCgroup.
- #register(key, value) ⇒ Object
Constructor Details
#initialize(name: "haconiwa-#{$$}", pid: $$) ⇒ SmallCgroup
Returns a new instance of SmallCgroup.
24 25 26 27 28 |
# File 'lib/haconiwa/small_cgroup.rb', line 24 def initialize(name: "haconiwa-#{$$}", pid: $$) @name = name @pid = pid @active_dirs = [] end |
Class Attribute Details
.fs_root ⇒ Object
Returns the value of attribute fs_root.
7 8 9 |
# File 'lib/haconiwa/small_cgroup.rb', line 7 def fs_root @fs_root end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/haconiwa/small_cgroup.rb', line 29 def name @name end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
29 30 31 |
# File 'lib/haconiwa/small_cgroup.rb', line 29 def pid @pid end |
Class Method Details
.register_at_exit(pid: nil, name: nil, dirs: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/haconiwa/small_cgroup.rb', line 9 def register_at_exit(pid: nil, name: nil, dirs: nil) at_exit do dirs.each do |dir| begin cleanup = fs_root.join(dir, name) FileUtils.rmdir(cleanup) rescue STDERR.puts "Failed to remove: #{cleanup}" end end end end |
Instance Method Details
#activate(dir) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/haconiwa/small_cgroup.rb', line 31 def activate(dir) dirroot = root_of(dir) FileUtils.mkdir_p dirroot append_write dirroot.join("tasks"), self.pid @active_dirs << dir end |
#activated?(dir) ⇒ Boolean
38 39 40 |
# File 'lib/haconiwa/small_cgroup.rb', line 38 def activated?(dir) @active_dirs.include? dir end |
#register(key, value) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/haconiwa/small_cgroup.rb', line 42 def register(key, value) dir = key.split('.').first unless activated?(dir) activate(dir) end overwrite root_of(dir).join(key), value end |