Re: JUJU_UNIT_NAME no longer set in env
On 23 May 2017 at 14:12, Jay Wrenwrote: > 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: > ah yes, sorry, I missed the --unit bit. -- Nick Veitch, Documentation Canonical -- Juju mailing list Juju@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/juju
Re: JUJU_UNIT_NAME no longer set in env
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 Wrenwrote: > 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 > wrote: > >> >> >> On 23 May 2017 at 11:23, Junien Fridrick >> 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
Re: JUJU_UNIT_NAME no longer set in env
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 Veitchwrote: > > > On 23 May 2017 at 11:23, Junien Fridrick > 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/ > mailman/listinfo/juju > > -- Juju mailing list Juju@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/juju
Re: JUJU_UNIT_NAME no longer set in env
On 23 May 2017 at 11:23, Junien Fridrickwrote: > > 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/mailman/listinfo/juju
Re: JUJU_UNIT_NAME no longer set in env
On Tue, May 23, 2017 at 10:08:45AM +0100, Nick Veitch wrote: > I don't believe you can (usually) execute hooks properly e.g. via 'juju > run' or ssh, precisely because the hook doesn't then run in a hook context. > If you run 'juju debug-hooks' and wait for a hook to fire, then the various > $ENV variables should be available in that session. > > https://jujucharms.com/docs/stable/developer-debugging#the-'debug-hooks'-command You can run some hooks like config-changed with e.g. : $ juju run --unit foo/0 hooks/config-changed I _think_ you can't run relation hooks because you need extra context. I also _think_ you should be able to run an install hook with "juju run", as above. Running hooks this way won't trigger debug-hooks. Cheers -- Juju mailing list Juju@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/juju
Re: JUJU_UNIT_NAME no longer set in env
I don't believe you can (usually) execute hooks properly e.g. via 'juju run' or ssh, precisely because the hook doesn't then run in a hook context. If you run 'juju debug-hooks' and wait for a hook to fire, then the various $ENV variables should be available in that session. https://jujucharms.com/docs/stable/developer-debugging#the-'debug-hooks'-command On 23 May 2017 at 08:56, John Meinelwrote: > > I *think* the hook context actually runs in the directory just above > 'hooks', but I'm not 100% positive. > it does :) -- Nick Veitch, Documentation Canonical -- Juju mailing list Juju@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/juju
Re: JUJU_UNIT_NAME no longer set in env
So you're running the 'install' hook directly, are you currently in a 'juju debug-hooks' session, or are you just changing into that directory? Juju sets it during the run of a charm hook, but it is not set globally on the machine (we can't set UNIT globally anyway, because you can colocate many units on one machine). If you need to run the install hook, I *think* you could get into a charm context with "juju-run ???/install". I don't know whether you'd need to give the full path, just the last bit of the hook path, or what exactly. I *think* the hook context actually runs in the directory just above 'hooks', but I'm not 100% positive. John =:-> On Tue, May 23, 2017 at 9:49 AM, Ian Boothwrote: > FWIW, Juju itself still sets JUJU_UNIT_NAME > > https://github.com/juju/juju/blob/develop/worker/uniter/ > runner/context/context.go#L582 > > On 23/05/17 05:59, James Beedy wrote: > > Juju 2.1.2 > > > > I'm getting this "JUJU_UNIT_NAME not in env" error on legacy-non-reactive > > xenial charm using service_name() from hookenv. > > > > http://paste.ubuntu.com/24626263/ > > > > Did we remove this? > > > > ~James > > > > > > > > -- > 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
Re: JUJU_UNIT_NAME no longer set in env
FWIW, Juju itself still sets JUJU_UNIT_NAME https://github.com/juju/juju/blob/develop/worker/uniter/runner/context/context.go#L582 On 23/05/17 05:59, James Beedy wrote: > Juju 2.1.2 > > I'm getting this "JUJU_UNIT_NAME not in env" error on legacy-non-reactive > xenial charm using service_name() from hookenv. > > http://paste.ubuntu.com/24626263/ > > Did we remove this? > > ~James > > > -- Juju mailing list Juju@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/juju
JUJU_UNIT_NAME no longer set in env
Juju 2.1.2 I'm getting this "JUJU_UNIT_NAME not in env" error on legacy-non-reactive xenial charm using service_name() from hookenv. http://paste.ubuntu.com/24626263/ Did we remove this? ~James -- Juju mailing list Juju@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/juju
JUJU_UNIT_NAME no longer set in env
Juju 2.1.2 I'm getting this "JUJU_UNIT_NAME not in env" error on legacy-non-reactive xenial charm using service_name() from hookenv. http://paste.ubuntu.com/24626263/ Did we remove this? ~James -- Juju-dev mailing list Juju-dev@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/juju-dev