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

add a cron-like systemd::timer interface #374

Closed
anarcat opened this issue Aug 21, 2023 · 4 comments · Fixed by #419
Closed

add a cron-like systemd::timer interface #374

anarcat opened this issue Aug 21, 2023 · 4 comments · Fixed by #419
Assignees
Labels
enhancement New feature or request

Comments

@anarcat
Copy link

anarcat commented Aug 21, 2023

I'm looking at converting my cron resources into a systemd::timer but the interface to that resources is rather unwieldy. It assumes prior and rather intricate knowledge of the format of systemd unit files and makes the cron resource look extremely intuitive and fun in comparison (which is not a compliment).

I think there's room for "cron-like" timer interface. We're not talking about reinventing the wheel here, probably just a little template will do. An interface such as:

define systemd::unit::job(
    $command,
    $user => root,
    $interval => # [...] that is of course the hard part
) {

    systemd::timer { $name:
        # ....
    }
}

Wikimedia operations people actually did this in their own systemd module which, strangely, is not related to this module but shares a lot of the interfaces, see their systemd::timer::job resource. It does a lot more than just create a timer though: it includes things like logging, monitoring and so on, probably not something we want to merge as-is just now. I mostly cite it as an example of how things could be done.

It makes conversions much easier, here's a patch of one conversion. I particularly like the > /dev/null 2>&1 removal, personally. :)

I mostly open this to get feedback, I'm likely going to implement this on our side anyway, but I figured it could be useful for folks here if I send it as a PR instead of just our secret sauce. See our internal ticket as well.

@traylenator
Copy link
Contributor

@anarcat I think its a good idea.

Indeed95% of cron jobs are

  • run X
  • daily, weekly or every 2 minutes.
  • run as user Y
  • Maybe some random component.

Maybe this should be an interface in https://github.com/voxpupuli/puppet-cron -probably not.

@ekohl
Copy link
Member

ekohl commented Aug 21, 2023

I did write systemd::timer a while back, but what you're suggesting sounds like adding a systemd::manage_unit style layer on top. That sounds useful to me.

As reference: this was the original reason I wanted the systemd::timer resource: https://github.com/theforeman/puppet-puppet/blob/master/manifests/agent/service/systemd.pp. As you can see, https://github.com/theforeman/puppet-puppet/blob/b08528470b9a95ba659f308ca2cafc6bec084c37/templates/agent/systemd.puppet-run.timer.erb#L8 isn't really a complete implementation of the cron spec.

Perhaps it makes sense to write a cron2timer() function and leave it up to the end user to combine the two?

@anarcat
Copy link
Author

anarcat commented Aug 21, 2023

Maybe this should be an interface in https://github.com/voxpupuli/puppet-cron -probably not.

i would rather not. i would like to eventually remove that module if we stop using cron altogether, and putting the shim there would make that difficult.

thinking about this more: i think we should have a straight out compatibility shim in there. and yes, systemd doesn't provide the exact same interface, but we can let the user shoot themselves in the foot there, i think.

i would do a systemd::timer::cron define that would match the cron interface and shove that in a OnCalendar thing and call it a day, to be honest. that would sweep a lot under the rug (like syntax differences between OnCalendar and cron, email notifications and so on), but that's things i expect people would handle during the conversion. we could even have docstrings pointing out those caveats...

@TheMeier TheMeier self-assigned this Mar 2, 2024
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 2, 2024
This helper will allow to define a timer in a cron like way, and will
setup a crresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For addtional feaures the parameter `service_ovverides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
addtional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 2, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
@TheMeier
Copy link
Contributor

TheMeier commented Mar 2, 2024

I did create a MR as a proposal. I have been maintaining and using https://github.com/TheMeier/themeier-systemd_cron for years. This is an adaption of this module to fit inside puppet-systemd and make mine obsoletet 😄

@TheMeier TheMeier added the enhancement New feature or request label Mar 2, 2024
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 3, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 4, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
TheMeier added a commit to TheMeier/puppet-systemd that referenced this issue Mar 4, 2024
This helper will allow to define a timer in a cron like way, and will
setup a corresponding timer and service.
In basic usage it only requires a command, user, timerspec and an ensure
parameter.
For additional features the parameter `service_overrides`, `timer_overrides`,
`service_unit_overrides` and `timer_unit_overrides` can be used to define
additional aspects of the create units.
The correct order of the units is also ensured.

fixes voxpupuli#374
related to voxpupuli#287
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 a pull request may close this issue.

4 participants