Module: OsCtld::Container::Hook

Extended by:
OsCtl::Lib::Utils::Log
Defined in:
lib/osctld/container/hook.rb

Class Method Summary collapse

Class Method Details

.exist?(name) ⇒ Boolean

Check if a hook with given name exists

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


22
23
24
# File 'lib/osctld/container/hook.rb', line 22

def self.exist?(name)
  @hooks.has_key?(name)
end

.hooksHash<Symbol, Class>

Returns:

  • (Hash<Symbol, Class>)


16
17
18
# File 'lib/osctld/container/hook.rb', line 16

def self.hooks
  @hooks
end

.register(name, klass) ⇒ Object

Register hook

Parameters:

  • name (Symbol)
  • klass (Class)


10
11
12
13
# File 'lib/osctld/container/hook.rb', line 10

def self.register(name, klass)
  @hooks ||= {}
  @hooks[name] = klass
end

.run(ct, name, opts = {}) ⇒ Object

Run user-defined script hook for container

See module OsCtld::Container::Hooks for available hook names and options.

Parameters:

  • ct (Container)
  • name (Symbol)

    hook name

  • opts (Hash) (defaults to: {})

    hook options



33
34
35
# File 'lib/osctld/container/hook.rb', line 33

def self.run(ct, name, opts = {})
  Container::HookManager.run(ct, @hooks[name], opts)
end

.watch(hook, hook_path, pid) ⇒ Object

Spawn a thread that will wait for the results of an async hook

Parameters:



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/osctld/container/hook.rb', line 41

def self.watch(hook, hook_path, pid)
  Thread.new do
    Process.wait(pid)
    next if $?.exitstatus == 0

    log(
      :warn,
      hook.ct,
      "Hook #{hook.class.hook_name} at #{hook_path} exited with #{$?.exitstatus}"
    )
  end
end