by twinpeak · 2y ago · 0 comments
# Get the number of restarts for a service to see if it exceeds an arbitrary threshold.
systemctl show -p NRestarts "${SYSTEMD_UNIT}" | cut -d= -f2
# Get when the service started, to work out how long it's been running, as the restart counter isn't reset once the service does start successfully.
systemctl show -p ActiveEnterTimestamp "${SYSTEMD_UNIT}" | cut -d= -f2
# Clear the restart counter if the service has been running for long enough based on the timestamp above
systemctl reset-failed "${SYSTEMD_UNIT}"No comments yet.