| 1 | = Pre and post-configuration hooks on ncm-ncd = |
| 2 | |
| 3 | [[TracNav]] |
| 4 | |
| 5 | [[TOC(inline)]] |
| 6 | |
| 7 | == Introduction == |
| 8 | |
| 9 | We want to be able to take actions before and after components are executed, with no link to the profile. Use cases include: |
| 10 | |
| 11 | * Report the execution results to the monitoring right away. |
| 12 | * Freezing and unfreezing services in the members of an HA setup. |
| 13 | |
| 14 | 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. |
| 15 | |
| 16 | This came a long time ago, as part of our feedback during our LISA presentation. |
| 17 | |
| 18 | === When hooks will run === |
| 19 | |
| 20 | We'll run hooks as part of the `--configure` process only. We'll run them: |
| 21 | |
| 22 | * Before any components run (`run-init`). |
| 23 | * After all components have run (`run-finalize`) |
| 24 | |
| 25 | We may discuss also: |
| 26 | |
| 27 | * Before the execution of each component. |
| 28 | * After the execution of each component. |
| 29 | |
| 30 | But I'll implement these only if they are '''really''' needed. |
| 31 | |
| 32 | == Implementation == |
| 33 | |
| 34 | === Hook API === |
| 35 | |
| 36 | ==== run-init ==== |
| 37 | |
| 38 | The pre-run action will receive no arguments. If it fails, it shall abort the execution of any configuration modules. |
| 39 | |
| 40 | ==== run-finalize ==== |
| 41 | |
| 42 | The post-run 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. |
| 43 | |
| 44 | === Specifying the hooks === |
| 45 | |
| 46 | We'll specify hooks in `/etc/ncm-ncd.conf`. They will look like this: |
| 47 | |
| 48 | {{{ |
| 49 | #!ini |
| 50 | run-init-hook = <hook-name> |
| 51 | run-finalize-hook = <hook-name> |
| 52 | }}} |
| 53 | |
| 54 | === What a hook actually is === |
| 55 | |
| 56 | We have two options here. And I'll implement only one of them, what's the feeling of the community? |
| 57 | |
| 58 | ==== Option 1: Perl module ==== |
| 59 | |
| 60 | A Perl module inside, say, `NCD::Hooks` namespace. It provides `run_init` and `run_finalize` methods. |
| 61 | |
| 62 | ==== Option 2: an executable ==== |
| 63 | |
| 64 | 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. |