How to check if 'systemctl daemon-reload' is needed
Systemd may need to reload a part of the unit configuration if changes were made. To find out if the related systemctl daemon-reload
command is needed, the state of the individual units can be tested. This is done by querying the property using the --property=NeedDaemonReload option.
Testing a single service like nginx, can be done this way:
# systemctl show --property=NeedDaemonReload --value nginx.service
yes
This output will return a ‘yes’ or ’no’ value.
Check all services
In need for a one-liner to check if there is any service that was changed and requires systemctl to initiate the daemon-reload?
# for UNIT in $(systemctl list-units --type=service --all --legend=false --plain | awk '{print $1}'); do if [ "$(systemctl show --property=NeedDaemonReload --value "${UNIT}")" = "yes" ]; then echo "$UNIT is outdated, systemctl daemon-reload needed"; fi; done
nginx.service is outdated, systemctl daemon-reload needed