systemd-logind.service,获取当前设置?

Dam*_*les 6 systemd logind

logind.conf 页面说明了有关已编译默认值和具有优先级规则的多个配置文件的信息。所有这些让我很难弄清楚当前的设置是什么。有没有办法打印 systemd-logind.service 当前已加载并正在使用的当前设置?

n-t*_*hen 5

I don't know a way to show the currently loaded settings, but the next best thing is to use systemd-analyze:

systemd-analyze cat-config systemd/logind.conf
Run Code Online (Sandbox Code Playgroud)

As you probably already read in the manual:

Initially, the main configuration file in /etc/systemd/ contains commented out entries showing the defaults as a guide to the administrator.

So in /etc/systemd/logind.conf you can see the defaults and if you don't get any entries with systemd-analyze that are not commented out, those are still your settings, because with systemd-analyze you get all config-files shown at once, so if you have an additional drop-in configuration-file under /etc/systemd/logind.conf.d/*.conf it will also gets listed. E.g.:

[root@client systemd]# systemd-analyze cat-config systemd/logind.conf
# /etc/systemd/logind.conf
(...)
[Login]
#NAutoVTs=6
(...)
#SessionsMax=8192

# /etc/systemd/logind.conf.d/logind.conf
[Login]
HandlePowerKey=ignore
Run Code Online (Sandbox Code Playgroud)

So in this example only HandlePowerKey=ignore is set manually and overwrites the default HandlePowerKey=poweroff

If you only want to see the manually set non-defaults, just grep with an invert-match, e.g.

systemd-analyze cat-config systemd/logind.conf | grep -v "^#"
Run Code Online (Sandbox Code Playgroud)

Changed settings get loaded by restarting the service

systemctl restart systemd-logind
Run Code Online (Sandbox Code Playgroud)