[GH-ISSUE #588] [RFE] Include syntax/examples on how to trigger the checks with systemd times #431

Closed
opened 2026-02-25 23:42:26 +03:00 by kerem · 5 comments
Owner

Originally created by @e-minguez on GitHub (Dec 8, 2021).
Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/588

It would be nice to include some examples on how to use systemd timers to replace cron entries.

Originally created by @e-minguez on GitHub (Dec 8, 2021). Original GitHub issue: https://github.com/healthchecks/healthchecks/issues/588 It would be nice to include some examples on how to use systemd timers to replace cron entries.
kerem closed this issue 2026-02-25 23:42:26 +03:00
Author
Owner

@cuu508 commented on GitHub (Dec 8, 2021):

Hi @e-minguez, thanks for the suggestion!

Do you mean adding documentation / examples on how to convert OnCalendar syntax to an equivalent cron expression, that can be used in Healthchecks?

Ultimately I'd like to have OnCalendar syntax support in Healthchecks (including multiple OnCalendar schedules for a single check), but that would of course take a fair bit of work to implement ;-)

<!-- gh-comment-id:988932709 --> @cuu508 commented on GitHub (Dec 8, 2021): Hi @e-minguez, thanks for the suggestion! Do you mean adding documentation / examples on how to convert OnCalendar syntax to an equivalent cron expression, that can be used in Healthchecks? Ultimately I'd like to have OnCalendar syntax support in Healthchecks (including [multiple OnCalendar schedules for a single check](https://unix.stackexchange.com/a/461437/498198)), but that would of course take a fair bit of work to implement ;-)
Author
Owner

@e-minguez commented on GitHub (Dec 8, 2021):

Essentially it would be nice to have an example on how to create the systemd service & timer to replace cron entries :)
Currently the examples show how to do it using cron/bash/other languages and I guess it would be helpful to add a simple systemd timer example.
Thanks!

<!-- gh-comment-id:988936970 --> @e-minguez commented on GitHub (Dec 8, 2021): Essentially it would be nice to have an example on how to create the systemd service & timer to replace cron entries :) Currently the examples show how to do it using cron/bash/other languages and I guess it would be helpful to add a simple systemd timer example. Thanks!
Author
Owner

@LordMike commented on GitHub (Nov 4, 2022):

Chiming in to say that I'm moving over to systemd timers to get stuff like logging and easier start/end calls to HC.. And it'd be great to have a Simple | Cron | SystemD option for (expected) schedules :)

For reference, I'm currently doing my crons like below. It's what I have right now, but I'll probably be expanding on this as I go on. Systemd can do a lot of stuff, like running stuff in sequence, multiple timers, logging stuff, error handling, retries, ..

# /etc/systemd/system/my-cronjob.service
[Unit]
Description=My First Cronjob

[Service]
Type=oneshot

## Place the primary command in ExecStart. Depending on use case, bash or another shell may be irrelevant
ExecStart=/bin/bash -c "echo Hello world; sleep 10; do stuff; exit 0"

## ExecStartPre runs before, the "-" in the beginning is to let systemd continue even on non-zero exit
ExecStartPre=-/bin/bash -c "curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/SOMEID/start"

## ExecStopPost runs after, no matter if ExecStart was success or not. The "-" in the beginning is like ExecStartPre
ExecStopPost=-/bin/bash -c "curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/SOMEID/$EXIT_STATUS"

[Install]
WantedBy=multi-user.target

# /etc/systemd/system/my-cronjob.timer
[Unit]
Description=My First Cronjob Trigger

[Timer]
OnCalendar=weekly
Persistent=true

[Install]
WantedBy=timers.target

Once placed, do a systemctl daemon-reload

Docs:

<!-- gh-comment-id:1303604197 --> @LordMike commented on GitHub (Nov 4, 2022): Chiming in to say that I'm moving over to systemd timers to get stuff like logging and easier start/end calls to HC.. And it'd be great to have a `Simple | Cron | SystemD` option for (expected) schedules :) For reference, I'm currently doing my crons like below. It's what I have right now, but I'll probably be expanding on this as I go on. Systemd can do _a lot of stuff_, like running stuff in sequence, multiple timers, logging stuff, error handling, retries, .. ``` # /etc/systemd/system/my-cronjob.service [Unit] Description=My First Cronjob [Service] Type=oneshot ## Place the primary command in ExecStart. Depending on use case, bash or another shell may be irrelevant ExecStart=/bin/bash -c "echo Hello world; sleep 10; do stuff; exit 0" ## ExecStartPre runs before, the "-" in the beginning is to let systemd continue even on non-zero exit ExecStartPre=-/bin/bash -c "curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/SOMEID/start" ## ExecStopPost runs after, no matter if ExecStart was success or not. The "-" in the beginning is like ExecStartPre ExecStopPost=-/bin/bash -c "curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/SOMEID/$EXIT_STATUS" [Install] WantedBy=multi-user.target # /etc/systemd/system/my-cronjob.timer [Unit] Description=My First Cronjob Trigger [Timer] OnCalendar=weekly Persistent=true [Install] WantedBy=timers.target ``` Once placed, do a `systemctl daemon-reload` ## Docs: * Services: https://www.freedesktop.org/software/systemd/man/systemd.service.html * Timers: https://wiki.archlinux.org/title/systemd/Timers * Timers `OnCalendar` can be verified with tools like `systemd-analyze calendar "Mon,Tue *-*-01..04 12:00:00"`
Author
Owner

@djarbz commented on GitHub (Aug 9, 2023):

I wrap my systemd timer services with runitor. Works quite well to capture the log output and start/stop status.

But having support for On calendar syntax would be awesome.

<!-- gh-comment-id:1670531558 --> @djarbz commented on GitHub (Aug 9, 2023): I wrap my systemd timer services with runitor. Works quite well to capture the log output and start/stop status. But having support for On calendar syntax would be awesome.
Author
Owner

@cuu508 commented on GitHub (Oct 15, 2025):

There's now a docs page with examples here: https://healthchecks.io/docs/monitoring_systemd_tasks/

The "Usage Examples" dialog has snippets intended for copy-pasting. I don't think this would work too well for systemd timers, as the example would show just a fragment of the service file not the whole thing.

<!-- gh-comment-id:3405053378 --> @cuu508 commented on GitHub (Oct 15, 2025): There's now a docs page with examples here: https://healthchecks.io/docs/monitoring_systemd_tasks/ The "Usage Examples" dialog has snippets intended for copy-pasting. I don't think this would work too well for systemd timers, as the example would show just a fragment of the service file not the whole thing.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/healthchecks#431
No description provided.