59

I am running user-level services in Ubuntu 16.04 LTS. For example, I have my test.service located at ~/.config/systemd/user/test.service.

I was able to run the service by doing

systemctl --user start test.target

However, when I try to read its log using journalctl, I got this error message:

journalctl --user -u test.service
Hint: You are currently not seeing messages from other users and the system.
  Users in the 'systemd-journal' group can see all messages. Pass -q to
  turn off this notice.
No journal files were opened due to insufficient permissions.

How can I use journalctl for user's specific unit?

Alexis Wilke
  • 2,496

6 Answers6

37

On older systemd versions, you'll have to use journalctl --user --user-unit=SERVICENAME (on newer versions journalctl --user -u SERVICENAME will work fine).

However, this only works if the Storage directive of the [Journal] section of /etc/systemd/journald.conf is set to persistent (instead of auto or volatile). Reboot after editing the configuration file and the user will be able to see the journal.

More information: https://www.freedesktop.org/software/systemd/man/journald.conf.html https://lists.freedesktop.org/archives/systemd-devel/2016-October/037554.html

7

Add your user to the systemd-journal or adm groups. It can be done with either:

sudo usermod -a -G systemd-journal $USER

or

sudo usermod -a -G adm $USER

Log out and log back in and you'll have full access to systemd journals.

Reference: https://wiki.archlinux.org/title/Users_and_groups#User_groups

Majal
  • 228
2

I was not able to make it work with the --user and other such options. However, I can see the data when I use journalctl on its own. It includes all the logs, though. I can search the specific app I'm interested in and look at that output. To find the latest, I first go at the end of the file then search backward:

  1. Hit G to go to the end (it's a capital G)

  2. Hit ? and enter your apps name

It's not as practical, but on the device on which I work (a Jetson), that was pretty much the only way I found to make it work.

Alexis Wilke
  • 2,496
1

i had to do this:

# mkdir /var/log/journal
# systemd-tmpfiles --create
# journalctl --flush

after this, journalctl --user -u SERVICE works for me (RHEL 8.9)

source: https://github.com/systemd/systemd/issues/16141#issuecomment-642628111

nagu
  • 111
1

Having the same problem (cannot use journalctl --user), after a lot of try and error, I have found that for it to work correctly the user can not be a "system" user.

  • When the user had a UID of 998: the journal did not appear at /var/log/journal
  • After recreating the user with UID 1002: the journal appeared after reboot.

My config:

  • The unit files are in: ~/.config/systemd/user/
  • I have 'export XDG_RUNTIME_DIR="/run/user/nnnn"' in .bashrc
  • Forced Storage=persistent in /etc/systemd/journald.conf
  • The user does not have any special group (adm or systemd-journal)

The units are started during boot; with this:

[Install]
WantedBy=default.target

With this config, I just execute "journalctl --user" and it works.

(Running on Ubuntu 16.04.7 LTS)

I hope this help someone.

0

you can make a bash script that rans sudo journalctl with specific parameter, protect that script from writing, give specific permission to run that script as sudo with no password. add entry in /etc/sudoers as for example

ALL ALL = NOPASSWD: /etc/show_journal.sh

instead of ALL your can write a specific linux user

Nir O.
  • 121