Using with systemd timers

May 1, 2022 in memos.

I use to monitor several cronjobs and this works great.

Recently I have been using systemd timers instead of cronjobs but wanted to continue to use healthchecks with them. I accomplished this using ExecStartPre and ExecStartPost in the service file.

To add these checks to the dnf-automatic.service,

  1. Edit the service file systemctl edit dnf-automatic.service
  2. Add a [Service] section
  3. Add a ExecStartPre= and ExecStartPost directive calling
[root@mx1 dnf]# cat /etc/systemd/system/dnf-automatic.service.d/override.conf
ExecStartPre=/usr/bin/curl -fsS -m 10 --retry 5 -o /dev/null${UUID}/start
ExecStopPost=/usr/bin/curl -fsS -m 10 --retry 5 -o /dev/null${UUID}

By adding /start to the curl command, you can log the run time of the service.

I am sure there is a better way of doing this, but this is working well for me today.