database-relation-join not invoked

Tim Van Steenburgh tim.van.steenburgh at canonical.com
Thu May 25 20:31:03 UTC 2017


On Thu, May 25, 2017 at 12:59 PM, Giuseppe Attardi <giuseppe.attardi at garr.it
> wrote:

> I have written a charm for OpenStack Gnocchi.
> The service requires a postgresql database relation.
>
> The start hook fails, of course, because the relation is not set.
>
> I expected that, but I expected that when I issue
>
>         juju add-relation gnocchi postgresql:db
>
> it will invoke the database-relation-joined hook, which does set the
> required parameter and then start would work.
> However the hook is not invoked: as a sanity check I set a juju-log
> message in it and it does not run at all.
>
> Is it correct to assume that add-relation will always trigger
> database-relation-join?
>

Yes it will. Assuming your relation is named 'database', then the
database-relation-joined will be triggered when that relation is
established. For more help debugging you may need to post a link to your
code.


> A second question, I would like to avoid to start the service until the
> relation has been joined.
> What is the best way to test for the relation to be present?
>

You should start the service in the database-relation-changed hook handler,
once you have received all necessary relation data.


>
> I tried with
>
>         db=`relation-get -r database host`
>
> but it fails with:
>
>         INFO start error: invalid value "database" for flag -r: invalid
> relation id
>
> I am using juju-2.1.2
>
> Thanks for the help.
>
> — Beppe Attardi
> --
> Juju mailing list
> Juju at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/
> mailman/listinfo/juju
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20170525/be3d8db5/attachment.html>


More information about the Juju mailing list