wiki:Development/Features/PrePostActionsNCMNCD

Version 1 (modified by munoz, 11 years ago) (diff)

--

Pre and post-configuration hooks on ncm-ncd

Introduction

We want to be able to take actions before and after components are executed, with no link to the profile. Use cases include:

  • Report the execution results to the monitoring right away.
  • Freezing and unfreezing services in the members of an HA setup.

Users should be able to specify the actions that need to be taken. However, these actions will not receive any $config-like object, or any profile representation.

This came a long time ago, as part of our feedback during our LISA presentation.

When hooks will run

We'll run hooks as part of the --configure process only. We'll run them:

  • Before any components run (run-init).
  • After all components have run (run-finalize)

We may discuss also:

  • Before the execution of each component.
  • After the execution of each component.

But I'll implement these only if they are really needed.

Implementation

Hook API

run-init

The pre-run action will receive no arguments. If it fails, it shall abort the execution of any configuration modules.

run-finalize

The post-run will receive the execution status (%global_status variable in NCD::ComponentProxyList::executeConfigComponents) as its only argument. If it fails, ncm-ncd will exit with a special exit code.

Specifying the hooks

We'll specify hooks in /etc/ncm-ncd.conf. They will look like this:

run-init-hook = <hook-name>
run-finalize-hook = <hook-name>

What a hook actually is

We have two options here. And I'll implement only one of them, what's the feeling of the community?

Option 1: Perl module

A Perl module inside, say, NCD::Hooks namespace. It provides run_init and run_finalize methods.

Option 2: an executable

Perl is not the favourite language of many contributors, and they prefer to be able to write their hooks in a different language. Any scripted hook that requires arguments would receive them as a JSON object via STDIN.