hook name restrictions
Clint Byrum
clint at ubuntu.com
Sat Nov 10 00:47:15 UTC 2012
Excerpts from William Reade's message of 2012-11-09 14:12:20 -0800:
> Hey all
>
> Recently I restricted the allowable names in charms' hooks directories,
> such that "juju-"-prefixed files were disallowed. It was mentioned at
> the time that it would be nice to restrict the names still further, and
> it only just crossed my mind that this is trivially easy: the *only*
> acceptable hook names are:
>
> * install
> * start
> * config-changed
> * upgrade-charm
> * stop
>
> ...and, for each of the relations defined by the charm:
>
> * <name>-relation-joined
> * <name>-relation-changed
> * <name>-relation-departed
> * <name>-relation-broken
>
> ...and any time we're inspecting a charm, we have access to the metadata
> and can easily determine what relation names are in play.
>
> I haven't looked through the charms to see what would be broken by this
> restriction, but it honestly feels like a Good Thing to me for the
> following reasons:
>
> * we might want to define new hooks; if we allow charms to keep any
> old junk in their hooks directories, we run the risk of name
> collisions, and that will be a tedious hassle
> * being able to see by inspection what events a charm responds to --
> and, as importantly, what events it does *not* respond to -- is
> valuable, and becomes much easier if readers can guarantee that any
> file in the hooks directory corresponds to an actual hook
>
> Can anyone think of a reason not to make this change?
>
I think you're absolutely right. However, it needs to be a "WARN" at
first, or a new "format" version should be used to control it.
I'd say close to 50% of the official charms have other files in the
hooks directory. This stems from the common pattern of making one big
script that is run for every hook via symlink.
If you do this, it would be quite helpful to also take a look at this
idea I put forth a while ago:
https://bugs.launchpad.net/juju/+bug/1009687
This would allow cleaning up the hooks directory without making the
desired effect (one script to control execution of all hooks) overly
complicated.
More information about the Juju-dev
mailing list