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

.hooksArray<Symbol>

Returns:

  • (Array<Symbol>)


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 = {})
  @hooks[name].run(ct, opts)
end

.watch(hook, pid) ⇒ Object

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

Parameters:



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

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

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