New health check for cron containers

This tiny script ensures we:
- have a crontab for a specified user
- this crontab isn't empty

If we don't pass a user, it defaults to root.
The emptyness takes into account puppet comments, thus we count
the lines without any leading '#'. By default, puppet adds
some environment variables before the command itself, thus we want
to have at least 2 uncommented lines.

Change-Id: I8ee23f05a2925a20d003dd85b6095fd0b559a23a
This commit is contained in:
Cédric Jeanneret 2019-04-10 10:26:30 +02:00
parent 3300af4827
commit b6921c6e96
2 changed files with 13 additions and 0 deletions

10
healthcheck/cron Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
file="${1:-root}"
if [ -f /var/spool/cron/${file} ]; then
nb_lines=$(grep -cEv '^#' /var/spool/cron/${file})
if [ $nb_lines -ge 2 ]; then
exit 0
fi
fi
exit 1

View File

@ -0,0 +1,3 @@
---
features:
- new health check for "cron" containers, ensuring it exists and has content