juju run --application runs as every unit of the application, thus we have
individual units (if you have 2 units of an application on a machine it
will run twice on that machine). 'juju run --unit" obviously runs as a
unit. 'juju machine' can't, because we don't have any unit associated with
it.

John
=:->


On Tue, May 23, 2017 at 5:12 PM, Jay Wren <jay.w...@canonical.com> wrote:

> 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.vei...@canonical.com>
> wrote:
>
>>
>>
>> On 23 May 2017 at 11:23, Junien Fridrick <junien.fridr...@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@lists.ubuntu.com
>> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailm
>> an/listinfo/juju
>>
>>
>
> --
> Juju mailing list
> Juju@lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/
> mailman/listinfo/juju
>
>
-- 
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju

Reply via email to