AnalogJ / scrutiny

Hard Drive S.M.A.R.T Monitoring, Historical Trends & Real World Failure Thresholds
MIT License
5.08k stars 165 forks source link

[BUG] - Cron Interval is Not Working with Custom Configuration #576

Closed xaqpuyrthnbg closed 7 months ago

xaqpuyrthnbg commented 7 months ago

Describe the bug Using the master-omnibus image, I cannot manually set the cron interval using the environment variable == COLLECTOR_CRON_SCHEDULE: ' /1 *' in my docker-compose yaml. As s scrutiny user, if I set this variable it updates every minute despite the configuration set.

Scrutiny cron config:

correctly route collector logs (STDOUT & STDERR) to Cron foreground (collectable by Docker STDOUT)

cron schedule to run daily at midnight: '0 0 *'

System environmental variables are stripped by cron, source our dump of the docker environmental variables before each command (/env.sh)

* */1 * * * root . /env.sh; /opt/scrutiny/bin/scrutiny-collector-metrics run >/proc/1/fd/1 2>/proc/1/fd/2

An empty line is required at the end of this file for a valid cron file.

Even after confirming above that the cron entry is correct, the collector runs every minute. With zero custom configuration and cron set to default, the cron job does not run at 0 0 * either.

I moved this known good config to a new server and have started experiencing this issue recently.

Expected behavior As a scrutiny user, I should be able to manually set the cron interval with an environment variable in my docker-compose.yaml and have it run hourly.

YAML

scrutiny: container_name: scrutinyv2 environment: COLLECTOR_CRON_SCHEDULE: ' /1 *' image: ghcr.io/analogj/scrutiny:master-omnibus cap_add:

Log Files N/A - I receive SMART data on the drives.

SeanChengN commented 7 months ago

Run it every hour on the hour, try this: "0 /1 " It will run from 0 o'clock.

I found that custom start time will cause it not to work, For example, starting from 3 o'clock, it will be executed every 6 hours: "0 3/6 " "0 3,9,15,21 "

The expression is valid if no start time is set: "0 /6 "

xaqpuyrthnbg commented 7 months ago

Hi, @SeanChengN. I did make a mistake when creating that cron variable, but I have fixed it and after waiting an hour and verifying the config inside the container, I can say that its still not running hourly despite the yaml or the cron.d/scrutiny inside the container.

Current yaml config changes the cron.d/scrutiny file: environment:

cron.d/scrutiny: command (/env.sh) '0 /1 ' root . /env.sh; /opt/scrutiny/bin/scrutiny-collector-metrics run >/proc/1/fd/1 2>/proc/1/fd/2

If I remove the environment attribute ( - COLLECTOR_CRON_SCHEDULE= '0 /1 '), it runs as expected every 24 hours at 00 00.

AnalogJ commented 7 months ago

Hey @SeanChengN @xaqpuyrthnbg

Unfortunately the cron schedule can only be set before the first start - https://github.com/AnalogJ/scrutiny/blob/a3dfce3561bcddcd8b70e4e7f483e22594c8af4d/rootfs/etc/cont-init.d/50-cron-config#L9

After the first start, the placeholder variable is replaced in the cron configuration file, and subsequent changes are ignored.

xaqpuyrthnbg commented 7 months ago

Thanks for the help @AnalogJ @SeanChengN