Finding out the service name from within a hook

Stuart Bishop stuart.bishop at canonical.com
Mon Oct 20 14:43:21 UTC 2014


On 20 October 2014 19:00, Andreas Hasenack <andreas at canonical.com> wrote:
> On Mon, Oct 20, 2014 at 9:55 AM, Christopher Glass <tribaal at gmail.com>
> wrote:
>>
>> Y's unit name should be accessible through "$JUJU_REMOTE_UNIT" from
>> X's relation-joined hook.
>> See
>> http://juju-docs.readthedocs.org/en/latest/internals/unit-agent-hooks.html
>
> I tried that, but got in the weird situation where it's possible for a
> relation to exist, but no units be part of it.
>
> In other words, if relids = relation_ids(name) and relids is not null, it's
> possible for relation_list(relids[0]) to be empty.


If you are in foo-relation-joined or foo-relation-changed, then
$JUJU_REMOTE_UNIT should certainly be set. I can imagine that
relation_list might not list that unit yet, as the other end might not
have had a chance to join the relation yet, but the JUJU_REMOTE_UNIT
environment variable is part of the contract.

-- 
Stuart Bishop <stuart.bishop at canonical.com>



More information about the Juju mailing list