Module: OsCtld::Hook
- Extended by:
- OsCtl::Lib::Utils::Log
- Defined in:
- lib/osctld.rb,
lib/osctld/hook.rb
Defined Under Namespace
Classes: Base, Manager, Script
Class Method Summary collapse
-
.exist?(event_class, hook_name) ⇒ Boolean
Check if a hook with given name exists.
- .hooks(event_class) ⇒ Hash<Symbol, Class>
-
.register(event_class, hook_name, hook_class) ⇒ Object
Register hook.
-
.run(event_instance, hook_name, **opts) ⇒ Object
Run user-defined script hook.
-
.watch(hook, hook_path, pid) ⇒ Object
Spawn a thread that will wait for the results of an async hook.
Class Method Details
.exist?(event_class, hook_name) ⇒ Boolean
Check if a hook with given name exists
26 27 28 |
# File 'lib/osctld/hook.rb', line 26 def self.exist?(event_class, hook_name) @hooks[event_class].has_key?(hook_name) end |
.hooks(event_class) ⇒ Hash<Symbol, Class>
19 20 21 |
# File 'lib/osctld/hook.rb', line 19 def self.hooks(event_class) @hooks[event_class] end |
.register(event_class, hook_name, hook_class) ⇒ Object
Register hook
11 12 13 14 15 |
# File 'lib/osctld/hook.rb', line 11 def self.register(event_class, hook_name, hook_class) @hooks ||= {} @hooks[event_class] ||= {} @hooks[event_class][hook_name] = hook_class end |
.run(event_instance, hook_name, **opts) ⇒ Object
Run user-defined script hook
See module Container::Hooks for available hook names and options.
37 38 39 |
# File 'lib/osctld/hook.rb', line 37 def self.run(event_instance, hook_name, **opts) Hook::Manager.run(event_instance, @hooks[event_instance.class][hook_name], opts) end |
.watch(hook, hook_path, pid) ⇒ Object
Spawn a thread that will wait for the results of an async hook
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/osctld/hook.rb', line 45 def self.watch(hook, hook_path, pid) Thread.new do Process.wait(pid) next if $?.exitstatus == 0 log( :warn, hook.event_instance, "Hook #{hook.class.hook_name} at #{hook_path} exited with #{$?.exitstatus}" ) end end |