I learned: file name of conf_regen hook matters for web UI and cron, but "yunohost tools regen-conf" always applies them?!

What type of hardware are you using: VPS bought online
What YunoHost version are you running: 12.1.39

(I solved the problem while writing this thanks to this PR by @abc from here :folded_hands: but it might still confuse someone else, so I’ll still post this.)

Lesson learned: the CLI will apply all hooks no matter how they are named, but the web UI does care about the names of the hook files :light_bulb:

Background: I have multiple scripts placed in /etc/yunohost/hooks.d/conf_regen, for example this one to set the postfix compatibility level and one for removing some nginx include lines as described here.

When I used yunohost tools regen-conf then these hooks did get used/applied successfully, and when I would run yunohost tools regen-conf --with-diff --force --dry-run again it would show nothing to be changed.

However, whenever I did something in the web interface that triggers conf_regen then the hook scripts were not used at all, so the config files went back to not have the modifications I want :thinking: This even affected config files in other parts, for example modifying the URL path in the redirect app not only regenerated the nginx config files, but also /etc/postfix/main.cfwhere then the line compatibility_level=3.6 was no longer there as the above mentioned hook is no loner used. (The hooks were also ignored when some cron job once per day regenerated config files.)

After a lot of guessing I realized that my hook files did not follow the naming pattern that @abc explained in the above mentioned post. So this helped:

mv 20-set-postfix-compatibility_level.sh 20-postfix_compatibilitylevel

(And similar for other scripts, comparing the numbers and names to what is in /usr/share/yunohost/hooks/conf_regen.)

The question remainds why the CLI did then use the hooks even with the “wrong” names. Does this mean that the CLI is less picky and just runs all the hook scripts, no matter how they are named? Are there two different codepaths for what the CLI tool does and what the web UI does? My assumption before was that they would run the same things actually.

Glad I could help. Unfortunately, I cannot answer your question

I don’t understand, that shouldn’t be the case.

root@metyun:/etc/yunohost/hooks.d/conf_regen# mv 20-postfix_compatible 20-set-postfix-compatibility_level.sh
root@metyun:/etc/yunohost/hooks.d/conf_regen# yunohost tools regen-conf postfix
Succès ! La configuration a été mise à jour pour 'postfix'
postfix: 
  applied: 
    /etc/postfix/main.cf: 
      status: updated
  pending: 
root@metyun:/etc/yunohost/hooks.d/conf_regen# grep compatibility /etc/postfix/main.cf
root@metyun:/etc/yunohost/hooks.d/conf_regen# mv 20-set-postfix-compatibility_level.sh 20-postfix_compatible
root@metyun:/etc/yunohost/hooks.d/conf_regen# yunohost tools regen-conf postfix
Succès ! La configuration a été mise à jour pour 'postfix'
postfix: 
  applied: 
    /etc/postfix/main.cf: 
      status: updated
  pending: 
root@metyun:/etc/yunohost/hooks.d/conf_regen# grep compatibility /etc/postfix/main.cf
compatibility_level = 3.6

This test show that 20-set-postfix-compatibility_level.sh don’t add compatibility_level = 3.6. The good syntax 20-postfix_compatible add it.

Could you try this test and post the result please?

Thanks for the suggestion! In your test you are running yunohost tools regen-conf postfix which indeed will not use a wrongly named hook. But when running yunohost tools regen-conf to regenerate everything then also the wrong named hook gets used:

root@myhostname:/etc/yunohost/hooks.d/conf_regen# yunohost tools regen-conf postfix --with-diff
root@myhostname:/etc/yunohost/hooks.d/conf_regen# mv 21-postfix_compatibilitylevel 21-set-postfix_compatibilitylevel
Success! Configuration updated for 'postfix'n# yunohost tools regen-conf postfix --with-diff
postfix: 
  applied: 
    /etc/postfix/main.cf: 
      diff: @@ -187,5 +187,3 @@
 
 
 
-
-compatibility_level=3.6
      status: updated
  pending: 
root@myhostname:/etc/yunohost/hooks.d/conf_regen# yunohost tools regen-conf --with-diff
Success! Configuration updated for 'postfix'
postfix: 
  applied: 
    /etc/postfix/main.cf: 
      diff: @@ -187,3 +187,5 @@
 
 
 
+
+compatibility_level=3.6
      status: updated
  pending: 
root@myhostname:/etc/yunohost/hooks.d/conf_regen# 

I guess some of the relevant code is here in regenconf.py where all_available_conf_regen_categories is used :thinking: but It don’t understand how it all works.

You’re right, it’s the same for me. I don’t have the skills to read the code and understand if it is intentional ( I don’t think so)

1 Like