borksh / bork

The Bash-Operated Reconciling Kludge
https://bork.sh
Apache License 2.0
23 stars 6 forks source link

(feature) (types) ok cron #20

Open lucymhdavies opened 3 years ago

lucymhdavies commented 3 years ago

Something which would be useful:

ok cron 0 * * * * ~/bin/foo

I can do stuff myself with something like:

ok check "crontab ~/git_src/dev_utils/cron/crontab"

but given I probably want to merge a bunch of crons together... something within bork to handle this would be useful

lucymhdavies commented 3 years ago

I'm actually doing this for the moment, so I can pre-populate crons based on one global cron file:

ok check "crontab -l"
if check_failed && satisfying; then
    ok check "crontab ~/git_src/dev_utils/cron/crontab"
fi

I'll worry about per-box crons when it becomes a problem (and maybe submit a PR to Bork to add the feature)

skylarmacdonald commented 3 years ago

Note to future self: look at the way Ansible does this. It puts a specific known-format comment above the cron line to keep track of it. Maybe bork could do something similar?

lucymhdavies commented 2 years ago

This works better than my version from https://github.com/borksh/bork/issues/20#issuecomment-817173654

ok check "diff -q <(crontab -l) $DEV_UTILS_DIR/cron/crontab"
if check_failed && satisfying; then
    ok check "crontab $DEV_UTILS_DIR/cron/crontab"
fi

Actually does a proper diff of the current crontab and the crontab file.

Short term, I'm thinking combining a bunch of files, then doing a diff.

skylarmacdonald commented 2 years ago

That's a good idea. For the actual type, though — for the purposes of keeping the types idempotent and stateless — I think we will just have to write out each individual crontab line as its own ok cron assertion, and Bork can check if there is anything like it in your crontab (and add it if not). I believe you can pipe stuff into crontab - so that might be the way (though would need to be careful about making sure we are appending to the crontab instead of replacing it wholesale…)