= Pre and post-configuration hooks on ncm-ncd = [[TracNav]] [[TOC(inline)]] == 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. Access to the profile is restricted to configuration modules. 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 hooks: * before the execution of each component. * after the execution of each component. But I'll implement these two only if people show me '''immediate''' use cases for them. == Implementation == === Hook API === ==== run-init ==== The `run-init` hook will receive no arguments. If it fails, it shall abort the execution of any configuration modules, but `run-finalize` will still run. ==== run-finalize ==== The `run-finalize` hook will receive the execution status (`%global_status` variable in [https://github.com/quattor/ncm-ncd/blob/master/src/main/perl/ComponentProxyList.pm#L87 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: {{{ #!ini run-init-hook = run-finalize-hook = }}} === What a hook actually is === We have two options here. And I'll implement only one of them, what's the preference 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.