0

I am working with systemctl to get value of the EnvironmentFile property from ssh.service unit file using the command systemctl show ssh.service -p EnvironmentFile but it returns empty result.

The unit file itself contains this property. For example my unit file looks like this (cat /lib/systemd/system/ssh.service):

[Unit]
Description=OpenBSD Secure Shell server
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run

[Service]
EnvironmentFile=-/etc/default/ssh
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify

[Install]
WantedBy=multi-user.target
Alias=sshd.service

Moreover if I do systemctl show ssh.service | grep EnvironmentFile I get:

EnvironmentFile=/etc/default/ssh (ignore_errors=yes)

Almost all other properties work as expected, for example systemctl show ssh.service -p After returns extended dependencies:

After=network.target auditd.service systemd-journald.socket basic.target sysinit.target system.slice

The same problem with the property ConditionPathExists, but in this case even grep doesn't show this property (systemctl show ssh.service | grep ConditionPathExists prints nothing).

Why does this happen? And how to get EnvironmentFile property from a unit file without using grep?

frist
  • 1,918
  • 12
  • 25

2 Answers2

1

I've reproduced the issue with the missing EnvironmentFile in systemd 229 and cross referenced the documentation for systemctl as well as the NEWS file from the latest release of systemd to see if there are mentions of this behavior being changed. There is not.

This appears to be a bug in systemd. The documentation for systemctl implies this will work, when reviewing the documentation for show and --property. As you noted, the property is definitely there if you grep for it.

I encourage you to search through the existing open issues for systemd to see if there's an already an open issue for this. If not, open a new Issue report.

If the behavior is working as intended, then the man systemctl docs should be updated to clarify that.

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49
1

As suggested by Mark Stosberg I tried to search for open issue related to this problem and I've found one which describes wrong autocompletion behavior regarding to Environment* properties.

Using busctl I've found out that the actual property name is EnvironmentFiles (busctl introspect org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/ssh_2eservice | grep EnvironmentFile):

.EnvironmentFiles                   property  a(sb)          1 "/etc/default/ssh" true                const

So if you need to get this property from systemctl you have to execute systemctl show -p EnvironmentFiles ssh.service (output below):

EnvironmentFile=/etc/default/ssh (ignore_errors=yes)
Community
  • 1
  • 1
frist
  • 1,918
  • 12
  • 25