Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crond: add support for crontab file only (on any OS) #289

Merged
merged 8 commits into from
Mar 22, 2024

Conversation

jkellerer
Copy link
Collaborator

@jkellerer jkellerer commented Nov 11, 2023

Implements #288

The PR allows to use an external scheduler that supports crontab format and adds the following configuration options:

global:
  # writes schedules to "file" and detects if a user column is needed
  # detection scan the file contents (header & entries, default to no)
  scheduler: "crontab: /path/to/crontab/file"

  # crontab with user column using user "root"
  scheduler: "crontab:root:/etc/cron.d/resticprofile"

  # crontab with user column using the current user
  scheduler: "crontab:*:/etc/cron.d/resticprofile"

  # crontab without user column
  scheduler: "crontab:-:/var/spool/cron/crontabs/user"

  # using the specified binary to read and save the crontab
  scheduler: "crond:/usr/bin/crontab"

(this is available on any OS)

The existing crond support using the crontab binary remains the same but it is now used as fallback when available (crontab binary is found) and systemd is not available.

waiting on #259 before implementing remaining tests

@jkellerer jkellerer force-pushed the ft/crontab-file branch 3 times, most recently from 214fe26 to a24579e Compare November 11, 2023 23:16
@creativeprojects creativeprojects added the enhancement New feature or request label Nov 11, 2023
@creativeprojects creativeprojects added this to the v0.25.0 milestone Nov 11, 2023
@jkellerer jkellerer force-pushed the ft/crontab-file branch 3 times, most recently from ef798d5 to 8c6cb4e Compare November 12, 2023 14:14
@creativeprojects creativeprojects modified the milestones: v0.25.0, v0.26.0 Feb 8, 2024
@creativeprojects creativeprojects modified the milestones: v0.26.0, v0.27.0 Feb 20, 2024
@creativeprojects
Copy link
Owner

This would also help with #321 as I realised that the crond implementation in busybox (alpine linux) has funny rules when trying to run as a non-root user. It doesn't work with the current implementation of using crontab to set or update the scheduling.

Allows to use an external scheduler that supports crontab format
the existing crond support using crontab binary remains unchanged for linux
@jkellerer jkellerer force-pushed the ft/crontab-file branch 2 times, most recently from 5f6d373 to 47243af Compare March 21, 2024 18:44
@jkellerer jkellerer marked this pull request as ready for review March 21, 2024 18:44
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 78.00000% with 66 lines in your changes are missing coverage. Please review.

Project coverage is 71.51%. Comparing base (85d5afc) to head (957db95).

Files Patch % Lines
crond/mock/main.go 0.00% 34 Missing ⚠️
schedule/handler_crond.go 48.00% 11 Missing and 2 partials ⚠️
crond/io.go 87.32% 5 Missing and 4 partials ⚠️
crond/crontab.go 91.78% 3 Missing and 3 partials ⚠️
schedule/handler.go 86.67% 2 Missing ⚠️
schedule/scheduler_config.go 95.56% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #289      +/-   ##
==========================================
+ Coverage   71.07%   71.51%   +0.44%     
==========================================
  Files         121      121              
  Lines       12394    12659     +265     
==========================================
+ Hits         8809     9053     +244     
- Misses       3189     3201      +12     
- Partials      396      405       +9     
Flag Coverage Δ
unittests 71.51% <78.00%> (+0.44%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jkellerer jkellerer force-pushed the ft/crontab-file branch 2 times, most recently from f4f0095 to 41108f6 Compare March 21, 2024 18:59
also adds more config options and examples in documentation
@jkellerer
Copy link
Collaborator Author

jkellerer commented Mar 21, 2024

Had tested all options manually, think it is ready now.

Copy link
Owner

@creativeprojects creativeprojects left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I'll try to use it with a non-root user container and see if that helps 👍🏻

Thanks 😉

-- Edit
I re-read the original post that triggered this PR... that's exactly what the OP wanted to do via Supercronic 🤦🏻 🙄

@jkellerer
Copy link
Collaborator Author

Yes. Supersonic is one option to have a compatible task scheduler that is OS independent (besides that it needs to run as service)

@jkellerer
Copy link
Collaborator Author

The use case with alpine should work as well. Had used busybox’s cron with custom crontab files previously.

@creativeprojects
Copy link
Owner

creativeprojects commented Mar 22, 2024

The use case with alpine should work as well. Had used busybox’s cron with custom crontab files previously.

Yes it works when running as root.
With this PR I managed to get resticprofile scheduled as a non-privileged user (using Supercronic).
I'll add a contrib for it.

I'm also tempted to provide another docker image with running resticprofile as a non-privileged user.

@jkellerer jkellerer merged commit 5739b13 into creativeprojects:master Mar 22, 2024
9 checks passed
@jkellerer jkellerer deleted the ft/crontab-file branch March 22, 2024 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants