我怎么知道是否需要运行 systemctl daemon-reload

red*_*888 8 linux bash systemd systemctl

有没有办法知道当前运行的配置已过时?有没有办法查看当前运行的配置并将其与文件进行比较?

在运行重新加载之前知道正在运行的配置是什么对于故障排除很有价值。如果命令会告诉我它是否真的更新了配置,这也很有价值。

Ale*_*hev 7

您可以通过命令检查加载的单元systemctl show <unit>.service。据我所知,没有工具可以检查单元文件中的更改。

您也可以运行此 bash 命令,for var in $(systemctl | grep running | awk '{print $1}'); do systemctl status $var | grep "changed on disk" | grep ".service"; done它会显示哪些文件已更改。

例子:

[root@centos-linux atolkachev]# for var in $(systemctl | grep running | awk '{print $1}'); do systemctl status $var | grep "changed on disk" | grep ".service"; done
Warning: nginx.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Run Code Online (Sandbox Code Playgroud)