JUJU_UNIT_NAME no longer set in env
Jay Wren
jay.wren at canonical.com
Tue May 23 13:12:57 UTC 2017
I was under the impression that `juju run --unit` does run in a hook
context. In fact, the help for `juju help run` explicitly says:
```
Commands run for applications or units are executed in a 'hook context' for
the unit.
```
A quick test:
```
> juju run --unit u4/0 'echo $JUJU_UNIT_NAME'
u4/0
```
So indeed, $JUJU_UNIT_NAME is set when using `juju run --unit`.
However, another quick test shows that it is not set in the machine case:
```
> juju run --machine 0 'echo $JUJU_UNIT_NAME'
```
But it is set when using --application, which surprised me:
```
juju run --application u4 'echo $JUJU_UNIT_NAME'
- Stdout: |
u4/0
UnitId: u4/0
- Stdout: |
u4/1
UnitId: u4/1
```
James, maybe you have used ssh to get shell on the machine instead of using
juju run?
--
Jay
On Tue, May 23, 2017 at 7:57 AM, Nick Veitch <nick.veitch at canonical.com>
wrote:
>
>
> On 23 May 2017 at 11:23, Junien Fridrick <junien.fridrick at canonical.com>
> wrote:
>
>>
>> You can run some hooks like config-changed with e.g. :
>>
>> $ juju run --unit foo/0 hooks/config-changed
>>
>
> You can run any hook like that, but if it requires a hook context (as in
> the example of trying to read $JUJU_UNIT_NAME ) it won't work. A lot of
> hooks in common charms don't need context, but you can't guarantee that.
>
> N.B. Also when using `juju debug-hooks` once any hook fires and you are in
> the hook environment, you can then execute any hook (not just the one that
> has been triggered), if you need to test them.
>
> --
> Nick Veitch,
> Documentation
> Canonical
>
> --
> 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/20170523/112bbdf1/attachment.html>
More information about the Juju
mailing list