0

(Edit: reworked question to avoid initial confusion with syslog)

A bit of bizarro systemd behaviour, which I'd like to either confirm as a bug, documentation failure or PEBCAK.

Consider a very simple unit that runs as root:

# cat > /etc/systemd/system/testecho.service <<EOF
[Service]
Type=oneshot
ExecStart=/bin/echo 'Hello world'
User=root
EOF
# systemctl daemon-reload

With User=root (or User unspecified) stdout goes to the journal tagged as the unit's, as one would expect:

# journalctl -u testecho -f &
# systemctl start testecho
Jan 21 19:37:33 atlassian-app01.phx7.llnw.com systemd[1]: Starting testecho.service...
Jan 21 19:37:33 atlassian-app01.phx7.llnw.com echo[13479]: Hello world
Jan 21 19:37:33 atlassian-app01.phx7.llnw.com systemd[1]: Started testecho.service.

However when a service is run as any non-root user, e.g. nobody, stdout is not tagged as the unit's, and won't appear if you run journalctl with -u:

# cat > /etc/systemd/system/testecho.service <<EOF
[Service]
Type=oneshot
ExecStart=/bin/echo 'Hello world'
User=nobody
EOF
# systemctl daemon-reload
# journalctl -u testecho -f &
# systemctl start testecho
Jan 21 19:38:56 atlassian-app01.phx7.llnw.com systemd[1]: Starting testecho.service...
Jan 21 19:38:56 atlassian-app01.phx7.llnw.com systemd[1]: Started testecho.service.

In fact stdout is going to the journal, but with no _SYSTEMD_UNIT tag. Stdout can be seen by leaving off the -u testunit:

# journalctl -f &
systemctl start testecho
# systemctl start testecho
Jan 21 19:42:04 atlassian-app01.phx7.llnw.com systemd[1]: Starting testecho.service...
Jan 21 19:42:04 atlassian-app01.phx7.llnw.com echo[13719]: Hello world
Jan 21 19:42:04 atlassian-app01.phx7.llnw.com systemd[1]: Started testecho.service.

This can also be confirmed by running journalctl -o json-pretty -f. When User= is non-root, there's no "_SYSTEMD_UNIT" : "testecho.service" field.

The docs on StandardOutput= say nothing of magical variance based on User, and nor do the docs for User=. All they say is that StandardOutput inherits DefaultStandardOutput, and defaults to journal.

Am I missing something? I note that my service's stdout is always goes to syslog, regardless of User

I've seen this on systemd 229 and 231 running on Ubuntu 16.04 and 16.10 respectively.

Thanks!

6
  • i'd suspect some permissions blocking nobody from writing into the journal. do you get the same issue with a real user? ... with a real user in the systemd-journal group (or similar)? – quixotic Jan 21 '17 at 5:36
  • Do you get the same result with logger and systemd-cat? – user1686 Jan 21 '17 at 11:16
  • @quixotic, it happens with any non-root user, in systemd-journal group or not. – Jeff Turner Jan 22 '17 at 0:09
  • An update: I've found that stdout is actually logged to the journal, but when User=nobody (or any non-root user) is specified, the message isn't tagged as belonging to the unit (testecho in the example). So the message can be seen with journalctl -f but not journalctl -u testecho -f. The lack of tag can be seen by running journalctl -o json-pretty - with User=root or User= omitted, one gets a "_SYSTEMD_UNIT": "testecho.service" tag, but no tag with User=nobody. Anyone know why this might be? – Jeff Turner Jan 22 '17 at 0:11
  • nice additional info. first thought: bug. second thought: _SYSTEMD_UNIT designation only used for system services? if you omit the User= declaration and run the service as your normal user (systemd --user) does it have the same effect? – quixotic Jan 22 '17 at 3:20
1

This sounds like a known issue that there are presently not plans to fix. See:

1
  • 1
    Confirmed, thanks! If I change ExecStart=/bin/echo 'Hello world' to ExecStart=/bin/bash -c "/bin/echo 'Hello world'; sleep 0.1", I get tagged output even with User=nobody. – Jeff Turner Jan 24 '17 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.