debug-hooks - strange behaviour

Bug #1981410 reported by Jordan Barrett
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Juju
Triaged
Wishlist
Unassigned

Bug Description

When I execute `juju debug-hooks`, sometimes I see the terminal screen with instructions (I think this is intended:
------------------------------------------------
This is a Juju debug-hooks tmux session. Remember:
1. ...

root@juju-c218bc-4:/var/lib/juju/agents/unit-wordpress-3/charm#
------------------------------------------------

However, at other times, I only see a blank screen with
------------------------------------------------
root@juju-c218bc-4:/home/ubuntu#
------------------------------------------------

I've noticed some other strange things. Sometimes while I am waiting at the second screen, the first screen will suddenly appear. Also, when I try to exit the first screen using `exit` or Ctrl-D, I am taken to the second screen (which sometimes will take me back to the first screen, making it hard to exit).

It seems like the second screen is calling the first screen as a "subshell" or something, but that it fails to do this sometimes. As for the timing, I think this is related to the status of the unit and/or if there is a hook running. It seems that I will get stuck at the second screen while a hook is running, and then once the hook finishes, it will take me to the first screen. I'm not 100% sure about this theory though.

This is using:
- Juju v3.0-beta2 (SHA 47e53008)
- Ubuntu 20.04 LTS
- GoLand 2022.1.3 integrated terminal

description: updated
Revision history for this message
John A Meinel (jameinel) wrote : Re: [Bug 1981410] [NEW] debug-hooks - strange behaviour
Download full text (4.2 KiB)

When you run `juju debug-hooks` we drop you into a tmux session with
multiple windows. The first window is just a session on the machine, the
latter ones are the actual hook executions. Indeed we will jump you from
the current session to the hook that is requested.
We need to sit you in *an* environment so that the session stays alive.

So I would say this is by design, I'm not sure your particular needs. It
can be true that you have a bunch of hooks pending you may struggle to exit
the current one and exit the terminal overall. (I believe as it is just
tmux, though, you can do ^B D to exit the session completely (it might be
^A, but I think that is the default for Screen while Tmux default is ^B))

On Tue, Jul 12, 2022 at 3:20 AM Jordan Barrett <email address hidden>
wrote:

> Public bug reported:
>
> When I execute `juju debug-hooks`, sometimes I see the terminal screen
> with instructions (I think this is intended:
> ------------------------------------------------
> This is a Juju debug-hooks tmux session. Remember:
> 1. ...
>
> root@juju-c218bc-4:/var/lib/juju/agents/unit-wordpress-3/charm#
> ------------------------------------------------
>
> However, at other times, I only see a blank screen with
> ------------------------------------------------
> root@juju-c218bc-4:/home/ubuntu#
> ------------------------------------------------
>
> I've noticed some other strange things. Sometimes while I am waiting at
> the second screen, the first screen will suddenly appear. Also, when I
> try to exit the first screen using `exit` or Ctrl-D, I am taken to the
> second screen (which sometimes will take me back to the first screen,
> making it hard to exit).
>
> It seems like the second screen is calling the first screen as a
> "subshell" or something, but that it fails to do this sometimes. As for
> the timing, I think this is related to the status of the unit and/or if
> there is a hook running. It seems that I will get stuck at the second
> screen while a hook is running, and then once the hook finishes, it will
> take me to the first screen. I'm not 100% sure about this theory though.
>
> This is using:
> - Juju v3.0-beta2 (SHA 47e53008)
> - Ubuntu 20.04 LTS
> - GoLand 2022.1.3 integrated terminal
>
> ** Affects: juju
> Importance: Undecided
> Status: New
>
> ** Description changed:
>
> When I execute `juju debug-hooks`, sometimes I see the terminal screen
> with instructions (I think this is intended:
> - ```
> + ------------------------------------------------
> This is a Juju debug-hooks tmux session. Remember:
> 1. ...
>
> - root@juju-c218bc-4:/var/lib/juju/agents/unit-wordpress-3/charm#
> - ```
> + root@juju-c218bc-4:/var/lib/juju/agents/unit-wordpress-3/charm#
> + ------------------------------------------------
>
> However, at other times, I only see a blank screen with
> - ```
> - root@juju-c218bc-4:/home/ubuntu#
> - ```
> + ------------------------------------------------
> + root@juju-c218bc-4:/home/ubuntu#
> + ------------------------------------------------
>
> I've noticed some other strange things. Sometimes while I am waiting at
> the second screen, the first screen will suddenly appear. Also, wh...

Read more...

Revision history for this message
Jordan Barrett (barrettj12) wrote :

Okay, it just seems quite glitchy from a user point of view. I think it would be better to only see the first screen with the instructions.

Revision history for this message
Jordan Barrett (barrettj12) wrote :

As a practical issue, if I end up on this screen:
------------------------------------------------
root@juju-c218bc-4:/home/ubuntu#
------------------------------------------------
I can't run any of the usual hook commands:
------------------------------------------------
# relation-get
relation-get: command not found
------------------------------------------------

Changed in juju:
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Jordan Barrett (barrettj12) wrote :

I'm still having to deal with this issue frequently. If I run debug-hooks, I will end up in a not-properly-initialised tmux environment:
--------------------------------------------------
root@controller-0:/var/lib/juju#
--------------------------------------------------

I'm not in the right directory, and more importantly, the environment is not properly set up, so I can't run any of the hooks. I get issues like "JUJU_UNIT_NAME not set" and so forth.

Sometimes I have to wait several minutes for the environment to jump to the "correct" screen (i.e. where it should have taken me initially:
--------------------------------------------------
This is a Juju debug-hooks tmux session. Remember:
1. ...
--------------------------------------------------

This is really impacting the usefulness of this debug-hooks tool for charm developers.

Revision history for this message
Paul Collins (pjdc) wrote (last edit ):

I was helping a colleague figure out juju debug-hooks today and it took me a very long time to realize that I completely misunderstood how it works.

I thought, because I had decided this was what I wanted, that I could run juju debug-hooks app/0 and get a place to invoke arbitrary hooks. Instead I had an empty root shell whose pwd was /home/ubuntu and whose environment didn't seem set up to support invoking hooks or actions.

Then I thought, well, I want to debug the config-changed hook, so let's run juju debug-hooks app/0 config-changed, which will surely do what I want. Same deal.

After a few minutes of pondering, a new tmux window popped up telling me that I could debug update-status, which is when the light dawned. (Clearly I gave up on the second command and tried the first one again!)

The text in the new window also linked to a document that explains this well: https://juju.is/docs/sdk/debug-a-charm

I think the following might be helpful:

1. Expand the juju debug-hooks summary to explain what it does and how it works, maybe:

    Summary:
    Launch a tmux session to debug hooks and/or actions as they occur.
    Whenever a hook or action is run, a new window will open in the correct context.
    By default, all hooks and actions will be debugged.
    Supply arguments to limit debugging to the given hooks and actions.

(That could use some editing, clearly!)

2. Print some text in window 0 explaining what will happen, and linking to the above document.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.