11

If I do:

journalctl -u my-service

then a Shift-F to follow while paging, how do I (interrupt to abort) without exiting the pager?

With less, I typically just ^C, but if I do that in journalctl, it exits the entire pager.

2 Answers 2

7

You are using less at that point, but ^C is behaving differently due to how it was invoked by journalctl. The flags that journalctl passes to less include the following defaults:

 FRSXMK

Of these, I think the "K" option applies here:

-K or --quit-on-intr Causes less to exit immediately (with status 2) when an interrupt character (usually ^C) is typed. Normally, an interrupt character causes less to stop whatever it is doing and return to its command prompt. Note that use of this option makes it impossible to return to the command prompt from the "F" command.

So, setting $SYSTEMD_LESS in your environment and omitting the "K" option should resolve the issue, it didn't work on my test on Ubuntu 16.04:

 SYSTEMD_LESS="FRSXM"journalctl -u nginx

However, you can get the behavior you want confirm that the K flag is related by comparing the behavior of the following variations:

# ^C after Shift-F does not completely quit
journalctl -u nginx | less -FRSXM

# ^C after Shift-F completely quits
journalctl -u nginx | less -FRSXMK
2
  • I have the same problem setting SYSTEMD_LESS, but I confirmed this does change the flags sent to less. You can check by finding the PID of less and doing hd /proc/<pid>/environ. Look for the environment variable LESS. It will be there but empty (normally it's FRSXMK). You can also type _K in less itself to see whether that flag is set. Normally it is. If you pass SYSTEMD_LESS= it isn't. I think the journalctl process is signaling the pager when it gets SIGINT, which is why less dies regardless of that setting.
    – user83640
    Nov 25, 2016 at 2:44
  • Here's a hacky proof-of-concept that shows how you can get around this: gist.github.com/chriskuehl/9ab4c74c19f2f4cb883744171335ac44
    – user83640
    Nov 25, 2016 at 3:07
0

I also just experienced this annoying quirk.
Setting SYSTEMD_LESS indeed does not work because journalctl will send a SIGTERM to the pager when it receives a ^C.

My "solution" was to use a bash alias like this:

alias log='SYSTEMD_COLORS=1 journalctl | less -FRSXM'

This overrides the default pager and does not exit when you interrupt follow.
The environment variable SYSTEMD_COLORS seems to be the only way to have colors and keep less running after a SIGINT.

This works on my Debian 9 installation.

1
  • Hmm, this stopped following. But so did journalctl | less, might be a bug.
    – clst
    Nov 25, 2018 at 23:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .