Inconsistencies between juju debug-hooks and "normal" hook environment

Merlijn Sebrechts merlijn.sebrechts at gmail.com
Tue Oct 6 14:49:20 UTC 2015


Thanks Cory!


The lack of both $HOME and $JUJU_HOME is the problem. How interesting that
~ still gets resolved even with $HOME unset...



Kind regards
Merlijn

2015-10-06 16:30 GMT+02:00 Cory Johns <cory.johns at canonical.com>:

> Merlijn,
>
> That is an annoying inconsistency.  It's probably related to debug-hooks
> bootstrapping itself via `juju ssh` which logs in as the ubuntu user since
> root ssh is disabled, as well as it being unlikely that the actual hook
> context is a login shell.
>
> I imagine the generate-config error is due to the lack of either $HOME or
> $JUJU_HOME being set.  I would recommend trying explicitly setting
> JUJU_HOME=/home/ubuntu before calling generate-config and see if that works
> around it.
>
> I've also created a bug against juju-core for this:
> https://github.com/juju/juju/issues/3449
>
> On Tue, Oct 6, 2015 at 10:06 AM, Merlijn Sebrechts <
> merlijn.sebrechts at gmail.com> wrote:
>
>>
>> Hi Matt
>>
>>
>> Thank you for your response. It was nice seeing you too!
>>
>> Let me explain my two, maybe related problems a bit more:
>>
>>
>> 1. Home directory is different between debug and non-debug hook context.
>>
>>    - Using the manual provider.
>>    - When deploying a Charm, the install hook is run as the "root" user.* "echo
>>    ~" prints "/root".*
>>    - When the install hook crashes, I connect to the unit using
>>    `debug-hooks` and restart the install hook as you described using  'juju
>>    resolved --retry unit/#'. After a while, tmux shows "[unit/0] 0:bash-
>>    1:install* " at the bottom and cwd is '/var/lib/juju/agents/unit-0/charm'.
>>    As I understand, I am now in the hook context, right? *However, "echo
>>    ~" prints "/home/ubuntu".* Even though the current user is root.
>>
>>
>>
>> 2. Something causes "juju init" to fail in non-debug hook context and
>> succeeds in debug hook context.
>>
>>
>>    - Using manual provider
>>    - Executing `juju init` or `juju generate-config` in a hook results
>>    in the error message `error: cannot determine juju home, required
>>    environment variables are not set`
>>    - Executing `juju init` or `juju generate-config` in the hook context
>>    using  `debug-hooks` and  'juju resolved --retry unit/#` succeeds.
>>
>>
>> My current workaround is to generate the initial juju config myself and
>> not use "juju generate-config". However, I'm not sure if this behavior is
>> intentional or a bug.
>>
>>
>> Thanks in advance!
>>
>>
>> 2015-10-06 15:37 GMT+02:00 Matt Bruzek <matthew.bruzek at canonical.com>:
>>
>>> Hell again Merlijn,
>>>
>>> It was nice to see you at the Charmer summit!  This is a very
>>> interesting use of Juju.
>>>
>>> What you are seeing is what we call a "hook context".  Hooks execute
>>> with root authority and have certain environment variables are set. This is
>>> so Juju commands and tools work correctly.  The debug-hooks command puts
>>> you into a "hook context" when you run  'juju resolved --retry unit/#'
>>>
>>> As I wrote all hooks are executed with these environment variables set.
>>> If you are running the install script manually outside of a hook context
>>> these environment variables would not be set.
>>>
>>> There is more information about the environment variables here:
>>>
>>> https://jujucharms.com/docs/devel/authors-hook-environment
>>>
>>> However, I don't see "JUJU_HOME" listed on this page. Perhaps you could
>>> give me more information on what variable is causing a problem and perhaps
>>> your hooks could set those values in the case where the script runs
>>> manually.
>>>
>>> Cheers!
>>>
>>>    - Matt Bruzek <matthew.bruzek at canonical.com>
>>>
>>> On Tue, Oct 6, 2015 at 5:07 AM, Merlijn Sebrechts <
>>> merlijn.sebrechts at gmail.com> wrote:
>>>
>>>> Hi
>>>>
>>>>
>>>> I'm developing a Charm that installs the Juju client, among other
>>>> things. I'm having some trouble getting this to work. When I use juju
>>>> debug-hooks and manually run the install hook, everything works fine.
>>>> However, when the hook is executed by Juju automatically, I get strange
>>>> errors such as "error: cannot determine juju home, required environment
>>>> variables are not set"
>>>>
>>>> Both the debug-hooks and the normal hook environment execute as root.
>>>> However, a lot of env vars are different, like the home dir.
>>>>
>>>> Debug-hooks:
>>>>     echo ~ : /home/ubuntu
>>>> hook env:
>>>>     echo ~: /root
>>>>
>>>> Is this intentional? This causes a lot of bugs that cannot be
>>>> reproduced by debug-hooks. Is there a way to solve  "error: cannot
>>>> determine juju home, required environment variables are not set"?
>>>>
>>>>
>>>>
>>>> Kind regards
>>>> Merlijn Sebrechts
>>>>
>>>> --
>>>> Juju mailing list
>>>> Juju at lists.ubuntu.com
>>>> Modify settings or unsubscribe at:
>>>> https://lists.ubuntu.com/mailman/listinfo/juju
>>>>
>>>>
>>>
>>
>>
>> --
>> 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/20151006/a8ca07d7/attachment.html>


More information about the Juju mailing list