9

Is there a way to know the current running config is outdated? Is there a way to view the current running config and compare it to the file?

It would be valuable for troubleshooting to know what the running config was before running reload. Also valuable if the command would tell me if it actually updated the config.

4 Answers 4

7

You can check loaded unit by command systemctl show <unit>.service. As far I know there is no tool to check changes in unit files.

As well you could run this bash command for var in $(systemctl | grep running | awk '{print $1}'); do systemctl status $var | grep "changed on disk" | grep ".service"; done it would show what files has been changed.

Example:

[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.
1

systemd doesn't provide out of the box support for displaying changed unit files, but you can use a bash script like this:

while read unit; do
    systemctl status $unit 2>&1 | awk '/changed on disk/ {print $2}'
done< <(systemctl list-unit-files | grep \.service | awk '{print $1}')
1

This line will do systemctl daemon-reload if needs to be run:

for service in $(systemctl | grep running | grep .service | awk '{print $1}'); do ! test "$mayreload" && systemctl status $var 2>&1 | grep -q "changed on disk" && && mayreload=1 && echo reloading systemctl && systemctl daemon-reload ; done
1
  • Is there any special reason that this has to be done in one line? Sure makes it hard to understand. For example there seems to be an error at && &&. May 2, 2021 at 11:07
0

This worked for me:

systemctl [--user] show [unit name] --property=NeedDaemonReload

or

systemctl [--user] show [unit name] | grep NeedDaemonReload=

It will output "NeedDaemonReload=yes" if it need to be reloaded.

If you use the grep method you can change the last part to grep NeedDaemonReload=yes or grep NeedDaemonReload=no to make it output nothing when it doesn't match (easier to use for scripting).

You also may want to run this with CanStart

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.