Does anyone know of a standalone program with functionality like systemd-timers?
Posted by kwhali@reddit | linuxadmin | View on Reddit | 59 comments
This is something I'd find handy for containers that cannot as easily leverage systemd-timers (at least anyone using an image via Docker AFAIK), and I suppose distros that insist on not using systemd.
cron (and variants) is alright, but sometimes I find myself needing to run a program at a recurring interval and would prefer to have the option of invoking the command as a service is started, and then repeating calls after N delay of time, rather than a variable amount of time until aligned with a cron expression schedule (at the hour or incremental interval, but that intervals become inconsistent if they don't cleanly segment the unit ceiling).
For context, I've also asked this same question over at r/docker.
I'd like to pair it with a service manager like supervisord for any services that lack a daemon/poll feature but should be run regularly at an interval. I know cron / supercronic effectively support this and can be considered "good enough" :\
Surely something like this exists out there already? Or would I need to DIY my own command wrapper for this?
vogelke@reddit
You could approach this by using a dated directory tree that gets cleared and recreated at boot, like /tmp. I have /var/run set up the same way because I don't need old pid files hanging around:
Create the top-level directory at boot time:
Then create a directory for your userid to keep people from stomping on each other's jobs:
Results:
Let's say you want to run something every 25 minutes. For demo purposes, write a message to syslog. At boot, it writes:
After that, every 25 minutes you want it to write:
The script being run can be simple. Call it "svc.sh":
You could also just move the script to its next timeslot if you're not planning on modifying it on the fly.
If the reboot time is 28 May 2026 03:50:00, root copies svc.sh to /var/run/recurring/kwhali/2026/0528/0350 and executes it as you immediately.
When it's done, a script called /var/run/recurring/kwhali/2026/0528/0415 exists with a modified syslog message.
The main driver for this process is something you run from cron once every minute. If /var/run/recurring/kwhali/YYYY/MMDD/HHMM exists and is executable, run it.
It's a bit of rigamarole, but if you have GNU date it should work for just about any sensible date interval. I use something like this in my home directory to show reminder popups in my XTerm at specific times.
bytezvex@reddit
This is clever as hell, but also kinda a lot of moving parts for what OP wants.
What you sketched out is basically a poor man’s timer wheel plus a mini job queue on top of cron. It works, but once you’re writing scripts that rewrite themselves into dated paths and need a 1-min cron driver, you’re already halfway to just using a tiny dedicated tool.
For OP’s use case in containers, this sort of pattern is probably easier to replace with something like:
s6,runit, or evenwatchplus a wrapper script, depending how fancy they need itYour idea is neat for reminders and one-off scheduled things though. Kind of like a personal atd with a filesystem UI.
kwhali@reddit (OP)
While I appreciate the detailed solution (I really do), it does go in the opposite direction of what I was seeking with reducing complexity.
Presently we have supervisord involved which simplifies running multiple instances of a service (with each instance number as context to match a config with that same suffix), we have a small bash script using a
whileloop withsleepto handle invoking a command at a recurring interval.I was seeking something like a command that basically wrapped another command to invoke repeatedly at the given interval. So installing a system package, or copying over a self-contained binary executable, rather than adding more scripts to maintain in the source repo (granted your example is fairly terse to integrate and an interesting approach).
Blank-Inspection13@reddit
snooze
kwhali@reddit (OP)
Already identified that in comment discussion. It seemed quite close but requires extra management of a timefile.
So I'd need to have a time file per instance of a command (running as a background task) if I'm scaling that task (such as different configuration per instance), and that time file would need mtime set to a date in the past for container startup (or additionally if wanting it to run the command immediately with container or manual service restart.
Then after task updating the mtime to now, so I would need to call a wrapper script, which means returning any non-zero exit status of the command not touch and ensuring sigterm is properly forwarded is handled accordingly too.
That neutralizes many of the perks as a result as it's main benefit over an equivalent bash script using a loop with sleep is I can use a time file that can conditionally run based on allowed slack when recovering? (useful if the command should be run consistently without the immediate invoke if manually restarting, or persisting the time file across container runs via a volume)
Without a time file the command uses cron scheduling behavior (already elaborated on why I don't like that in this scenario) and the sleep interval is handled before running the command (this is convenient / simpler, but is also why an immediate start is extra work).
snoozeis cool, just not really providing the improvement I am seeking. It relies on a process supervisor for the repeating aspect, which also handles any clean up of orphans and all that, so I just usebash -c 'my-command && sleep 25m'for example,snoozeisn't simpler than that unfortunately.1esproc@reddit
You're already using supervisord, just keep using that.
autorestart=trueto your program definition.ENV_SLEEP_INTERVAL(for example) and access via%(ENV_SLEEP_INTERVAL)sin yourcommand=config lineAll your stdout/stderr shit will bubble up to supervisord like you want
kwhali@reddit (OP)
Yeah I am already roughly doing that but when you add the sleep it can complicate the management?
If you sleep before the command, how would you be able to stop the service without waiting on sleep to complete since signals aren't forwarded?
If sleeping after (which I want anyway) I'm pretty sure the concerns with sleep are avoided with
execlike this:That will bubble up a non-zero exit status from the earlier command with the
&&short-circuit, but I don't know about forwarding a signal to my-command if it's presently processing at the time?In this case it's not a big deal but if it did take quite a while it wouldn't receive the signal unless you add a trap prior? The
execotherwise would ensure it was fine with the sleep and would exit that process immediately.I think with the above stdout/stderr from
my-commandwould work fine too, bit tired atm 😅I have mentioned the above somewhere before in an earlier comment, it's the closest solution that fits, assuming a process supervisor and a shell are present in the image.
1esproc@reddit
Set
stopsignaltoKILL? Why are you relying onbash -cand not just relying on shebang?kwhali@reddit (OP)
I guess setting
stopsignal=killis fine, given an orphan sleep process wouldn't be that bad.Not ideal though the command invoked spawned other child processes that became orphaned? I'm not too familiar with zombie processes, and while it may not matter in this case I would like to avoid that concern when adopting this elsewhere in other projects.
EDIT: You can skip ahead to the "Revised" section at the end. I just discovered supervisord can target the process group and send each process the configured
stopsignal, so that resolves that concern.If the script itself is
my-command && sleep 25m, does it really need a separate script file with a shebang when you can just inline it like I showed? What benefit is there?Reference - Existing implementation
supervisordconfig:getmail-service.sh(partial content shown):I'm not sure why the login shell was necessary (I am not the author of the script), presumably due to their use of bash or the
getmailprogram itself to ensure some ENV were set. - Theforloop can be removed along with--rcfileoption as that software has implemented functionality back in 2021 to iterate the--getmaildirfor individual configs instead. - Perhaps when initially contributed to the project in 2023 the debian package used might have been too old at the time, or the contributor and reviewer(s) were not aware of the functionality (the getmail6 project on Github only documents it in a changelog entry and raw HTML docs, while linking to online docs that were last updated in 2020).Simplified
So presumably this change to the supervisord config
commandwould be fine:Or keeping the existing
getmail-service.sh(but removing other stuff I didn't show, such as a stop method that callssupervisorctl, which has kinda prevented running this service as a non-root user):trapto kill the process group for the most part makes usingexecwithsleepredundant, so I could drop theexec.supervisordin this scenario, I could also replace the bashtrapwith the supervisor service settingstopasgroup=true(sendsSIGTERMto all process in the process group).UPDATE - Revised
Leaning into supervisord more, no need for
trap/execorset -e(since script is basic enough&&is sufficient?), so do away with that script and just inline a bash command like this?:I think that should work pretty well and meets my expectations AFAIK (a separate executable that doesn't depend upon
supervisord+bashwould be pretty sweet too though).1esproc@reddit
Killing the bash process running
sleepwon't leave an orphan, it'll terminate too even with SIGKILL.kwhali@reddit (OP)
Umm... No? Only if you pair it with
stopasgroup=true/killasgroup=true.I've verified with a basic script:
/tmp/verify.sh:Run
verify.sh:SIGTERMwas applied to children in the process group as expected.Now set
stopasgroup = false(default) andsupervisorctl update test-xyz, then re-run the verify script:SIGTERMwas not received, child processes continue to run despite the parent bash process was terminated.symcbean@reddit
You find it difficult to do this with cron?
kwhali@reddit (OP)
It's not an image for my personal use, if you are familiar with managing projects and dealing with users you'd be aware that users don't always walk the happy path, some make weird choices.
Timing requirements depends on what the task to run is. I've worked on microcontrollers with C where deterministic timing was crucial due to limited windows, and then there's services with background tasks where it's not that critical.
My question is probably better outlined at the r/docker post I linked. I have working solutions, I have just reached out to the community for alternatives that better align with what I'd like (systemd-timer like scheduling, consistent intervals, invoking the initial command at service startup, etc), and ideally there is a CLI program that'd just manage the interval and call the program.
With cron you add a job like you showed and beyond the timing caveats I've mentioned, stdout/stderr aren't piped back to the caller so a supervising process wanting the logs to manage isn't happening, instead cron likes to email the output.
Similarly if I want to stop the service, if that task is presently running are signals forwarded? No.
The bash script doing a while loop and sleep works good enough, I just wanted to know if there was an existing program out there that fit what I wanted or if I need to DIY that.
symcbean@reddit
We can only answer the question you ask. If you have requirements/constraints you don't mention in the question then you're not likely to get very good answers.
kwhali@reddit (OP)
While that's true, my experience is often if I'm too verbose and specific I also don't get much engagement. My replies are already quite verbose in the comments.
Sometimes through discussion that description of requirements/constraints becomes clearer/refined to communicate, as not everyone is on the same page (I'm not quite sure how to phrase this but I think you get what I mean).
I figured if I outlined roughly what I'm seeking: - Run a command at a recurring interval - Forward signals (notably SIGTERM), ensure stdout/stderr and the commands exit status if non-zero is captured; such that for the most part it's like running the command itself directly (it's just repeatedly called between the interval).
Along with citing what issues I had with other options I was already aware of (
cronbeing a common suggestion I still received).I also mentioned the desire to pair the usage with a process manager like
supervisord, and that ideally I'd love a systemd-timers alternative that is compatible with running in a container via Docker in a sane manner. systemd timers are much more featureful, so pragmatically I narrowed the scope down to a minimal set of what I want and didn't want.If I went over everyones feedback to be super verbose and thorough, it'd be quite a lot more noise for readers, and even with what information I did provide I still got plenty of comments going against the grain.
Hell one user insisted I use Quadlets, even after I clarified that I needed a solution not just for my personal use/deployment, but that worked in a container with broader compatibility, citing a real-world project example with 18k+ users that are predominantly using Docker.
For the real-world
getmailservice example, supervisord service + bash forsleephas resulted in moving away from the while sleep loop into a simple solution close to what I wanted:That works for me, meets my requirements/expectations.
A portable binary executable without depending upon Python and Bash would be better, but if I need that in future I can just write my own Rust program since there doesn't appear to be an existing established project on Github.
ritonlajoie@reddit
I read everything I am not sure why but my take on this if you are allergic to at, cron or other suggestions, make you own in python and call it a day
kwhali@reddit (OP)
I don't see how I'm allergic, if you really did read everything I've said on the matter (such as this comment) you'd know that I've made it clear why none of those are desirable.
So valid reasons equates to allergic? :\
Again, if you had read everything you'd have seen that I've said I'm comfortable to write such in Rust. I just reached out here to double check I'm not mistaken about no obvious program out there meeting my requirements.
For the example scenario that is discussed with
getmail, this has been simplified down to leaning into supervisord (Python program) and Bash (for handling the interval delay) as a terse implementation that meets the requirements I had.It roughly looks like this:
Close enough, for other projects where I want something lighter weight, I can write my own Rust program to do the same and publish that on Github for others to benefit from since such a solution appears to be lacking for whatever reason.
chock-a-block@reddit
cron?
kwhali@reddit (OP)
There are issues with cron, but the larger one for me was I want to start a container and have the command execute and then run again at a consistent interval from that point.
With cron I cannot ensure that unless the interval cleanly fits into the upper limit (like 5 minute increments into an hour). I did touch on this in my post, a more obscure interval like 25 minutes is already inconsistent even without taking the container startup offset into consideration.
If it were just for me to manage and deploy, I'd just pick a sane unit that fits in cron and that wouldn't be so bad (depending how important it is to run a recurring command from startup vs wait until aligned to the cron schedule), but the interval in this case can be configured by the user which equates to docs explaining the quirks with cron or dealing with "bug" reports when a user for whatever reason chose something odd like 25 minute intervals.
Systemd timers are really nice though, they avoid quite a few issues with cron especially more nuanced scheduling requirements (I think one often cited is daylight savings behaviour which last I recall cron implementations tend to handle poorly).
serverhorror@reddit
Seems what you want .... what am I missing?
kwhali@reddit (OP)
Basically it should be like running a command itself but with the ability to run it at a recurring interval.
RetroGrid_io@reddit
I do stuff like this all the time with cron.
/run/this/script.sh; echo $? > /path/to/lastrun.statusalso:
Yes it's old school, but it's incredibly simple, stable, and tested/debugged/used since 1995 or so.
imbev@reddit
kwhali@reddit (OP)
I've thought of doing the equivalent in my preferred language (Rust), I'd just have preferred an existing project since there might be some caveats I've not thought about if I DIY my own solution (generic for reuse rather than tailored to any specific project).
I'm just a bit surprised that there's not an established CLI tool for this functionality? Especially for forwarding signals and stdout/stderr which are related needs for this type of wrapper command.
serverhorror@reddit
You're asking for things were solved in multiple ways here.
Then you invalidate the answers with obscure reasons that are irrelevant for your description (daylight savings are irrelevant if you want to run something every N seconds) and miss others completely (like what happens if you send KILL, INT, ...) or what happens if it takes longer than your interval, should it kill the original job or start parallel executions?
I think you're overcomplicating the problem, just so a loop.
kwhali@reddit (OP)
I have provided a real scenario, but also expressed that I'm not seeking a solution just for that, but whenever I would like this functionality and would prefer systemd-timers over cron.
In the real scenario I already have a bash script that uses a trap so when the process is killed the child processes like my command or sleep receive the signal so processes are terminated and not orphaned. This bash script uses the suggested while loop and sleep pattern.
The main requirement is given an interval of time, after the command exits run the command again after that interval, repeat.
I'm not fussed about an overlap problem as that isn't happening processing isn't anywhere near as long as the interval, cron doesn't fix the overlap concern either though.
The secondary requirement is to treat this functionality like I were calling that command directly, so it is easy to integrate into a process supervisor with signals forwarded, stdout/stderr received for logs, exit status when non-zero, etc. I have said this multiple times and they're quite reasonable expectations.
atwith rescheduling itself was pretty good, but it has a daemon which complicated configuring which user to run as (vs what the supervisor could set), additionally it didn't seem straightforward to integrate for the supervisor to stop the queued job (eg viasupervisorctl stop service).There was a custom bash script using the date command and mkdir to form a filesystem hierarchy and persist the scheduling this way when invoking a wrapper script as a way to avoid the loop. It wasn't really satisfying the goals of simplifying the real world scenario for maintainers or my future usage elsewhere though.
I don't need solutions that are external to the container to manage it. That rules out some suggestions like ofelia or it's forks. This is meant to be setup and managed within the image, the user shouldn't have to think about it.
I need to support a broader range of runtimes, notably the well-established and popular Docker for the real scenario which is the bulk of actual users. That rules out podman / quadlets due to compatibility.
I don't feel that these are that obscure for reasons? That I'm invalidating them for the sake of it? I have lengthy replies to most, I explain why it's not what I'm looking for.
The bash script solution presently in use works well for the real world scenario, I'm just not personally fond of it and don't want that in any future scenarios in any other images I work on.
All I would like is a simple command covering the two requirements stated above really, I can write such a program myself, I just didn't want to take a NIH approach if there was something already suitable that I wasn't aware of.
perryurban@reddit
Why exactly don't systemd timers meet your requirements?
kwhali@reddit (OP)
You may not be familiar enough with containers? Docker doesn't integrate with systemd that well (you can make it work but it's a tad invasive IIRC). Pretty sure Podman however has implemented their runtime in a manner that it's minimal friction if any to support.
This differs from using a systemd timer on the host. The intent is the image is self-contained and the user doesn't have to setup much else on the host to utilize the image service, background tasks that run a recurring interval can be configured during container setup (config files via volume and ENV vars supported in docs), but aside from Docker itself (or Podman/Kubernetes) you don't need to rely on the host software like systemd interacting with the container and ensuring you keep that updated alongside the image.
The image does use cron for some background tasks, but I've tried to focus on my desire for alternative solutions that aren't cron (notably when I want to ensure the interval between runs to be reasonably consistent). The user doesn't have to really worry about these beyond the exposed config options, it's all handled for them.
If I could use systemd timers in the image in a way that less experienced users can just pull the image and
docker run my-imageor equivalent, that'd be great. I'm not willing however to mandate users reduce security of the container just so I can utilize systemd inside it though (the lack of it's availability for such images is something I'm rather unhappy about as I quite like systemd).If you know of a standalone implementation that could be used instead, that'd be neat :)
Eclipsez0r@reddit
Have a look at quadlet.
kwhali@reddit (OP)
I know of quadlets, the problem is when you build an image for public usage and want to support Docker users, they can't benefit from systemd support that podman has.
abotelho-cbn@reddit
To be honest it sounds like this container image is ripe with antipatterns to start. You're treating it like a full OS image running multiple applications?
kwhali@reddit (OP)
It doesn't, but I am tired of explaining that to people. A container should provide a single logical service.
Sometimes that's as simple as a single program / process which might spawn child worker processes (eg nginx), or a web service that has php (nginx + php-fpm) is an example of two distinct processes that could be run as separate containers but it adds more hassle (eg shared volume + distribution of project files from image into shared volume between containers) vs bundling into a single image where the unnecessary volume can be avoided.
In my case I've been commonly referring to a image that provides a mail server. Integration is much simpler bundled vs individual containers and a container that co-ordinates all the integration. Far simpler for users to configure and maintain on their end, especially upgrades where the user doesn't have to think about version compatibility across individual components and security in the configuration, etc.
18k+ stars is not something you get because of an anti-pattern. One of the most popular dockerised mail server options out there. It's been going strong for many years.
There are competing alternatives with far more complexity unloaded upon the user config wise and verbose compose files. Great if you're in need of that or want to stand firmly as a purist, not so much if you want to deploy at a small scale with minimal fuss.
It's also far easier to configure and deploy 2-3 instances of
docker-mailserverthan the competition. I regularly providecompose.yamlexamples for various config setups and reproductions that are simple copy/paste of that file alone and these are often smaller than a single multi-container msilserver config from competing projects.We cater to a demographic that prefer this approach I've described, I don't consider it an anti-pattern when it's providing a single logical service.
I typically do not encourage bulky images or mixed responsibilities. We still defer to separate containers if you're integrating a webmail service, or a GUI dashboard/admin service instead of using our CLI or configs. While we bundle a fair amount, each service can be enabled / disabled easily, you can choose to run them independently without our config management / decisions if you decide to, you aren't locked into a single container but we also advise using competitors when you want to run individual containers and know what you're doing.
If you choose to run separate containers you may find some integrations of the components will reduce security or add complexity / friction to setup securely. We rather avoid delegating that to our users where possible that are often not mail server experts or even that technically skilled (their backgrounds are diverse).
That said, such an image is not without it's challenges. Maintenance could be easier for me in some aspects by using separate containers, setup would be messy though.
abotelho-cbn@reddit
Quadlets. The answer is Quadlets. Not only does it solve your multi-process situation (pods), but it also solves your scheduling issue (systemd-timers).
Docker sucks. That's just the reality. As a product it just stinks in production deployments. Even as a single container, it lacks the integration necessary to run things reasonably on a single machine.
kwhali@reddit (OP)
You're welcome to your opinions, I'm not particularly interested in debating such. Podman and Quadlets are great, but I've also run into my fair share of issues with them and features that exist with Docker that simply were missing in Podman or buggy, not that Docker is any better on that front it's been hit or miss with both in my experience but hey I tinker and do niche things.
Anyway no podman and quadlets is not the magical answer. I have already stated why, this isn't a personal problem otherwise I'd do exactly as you suggest, it's a public image which if the name
docker-mailserverdoesn't make it clear enough is an image with Docker users (primarily Docker Compose, which happens to meet some expectations of mine that Quadlets doesn't fancy that).I can't just suddenly tell users of an 18k star project where barely any reports and discussions involve podman that Docker is no longer supported due to the decision to replace a small bash script with systemd-timers 🙄
Concern, service, phrase it how you like. The container provides a mail server, which like php-fpm and nginx, it's done for a good reason. I even elaborated on this which I assume you skipped over or actively chose to dismiss given your response.
If you don't know much about mail servers please don't try argue that you somehow know better, I've maintained the image for over 5 years, it's a successful project which I like to continue refining into a a better one to maintain and support users of it. Yes you can split it up into smaller containers, just like nginx and php-fpm can run in separate containers with added complexity / concerns when the split itself can be completely unnecessary.
abotelho-cbn@reddit
You can justify it as much as you want, but this problem you have exists because of the anti-patterns you are employing.
That's really all I have to say.
Cheers, good luck.
kwhali@reddit (OP)
Please tell me what the correct way is when supporting my 18k Docker users? Or are you insisting Docker itself is the anti-pattern now, so all those users should be forced to switch to quadlets?
1esproc@reddit
Not outside the container it shouldn't
syzygy78@reddit
Have you looked at "at"? You can specify execution time as an increment from 'now.' I've used it to create a three line pseudo-daemon which did a thing than scheduled itself to run again in x minutes. It's super than cron and works well in scripts.
kwhali@reddit (OP)
I have just had a quick look at
at, it seems to require a daemon though? The use ofnowwith the interval and having the command reschedule itself after is interesting but I guess quite similar to chaining on asleep 25mwith a process manager (when available) likesupervisordwith auto restart policies when a command exits?I think
atmight be viable in some scenarios, it's just the daemon dependency would presumably complicate things if I want to run the command under a different user? (su/runuseror similar can be used but gets more lengthy, especially if you already have a service/process manager in the mix with such support)I just found
snoozewhich seems interesting..Looking at the project README
-t timefileis needed to get immediate execution (creates a file and uses that empty file mtime attribute for comparison), and-M 25would be a 25 minute interval to run the command at.CardOk755@reddit
at does indeed use a daemon. It uses cron.
syzygy78@reddit
Actually it uses it's own atd daemon, and doesn't use crontab. They are similar but distinct.
CardOk755@reddit
My bad.
kwhali@reddit (OP)
The source has an
atddaemon but there is little interaction with cron? Comments refer to indirectly using crontabs?redundant78@reddit
Check out ofelia - it's basically a job scheduler designed specifically for docker environments. If you want something even simpler and just need "run X every N seconds starting now", honestly a bash
while true; do command; sleep N; donewrapped in supervisord is dead simple and gives you exactly the "start immediately then repeat" behavior you're describing.kwhali@reddit (OP)
I feel I should have cross-posted at this point 😅
Yes I'm aware of ofelia and I point that out at the equivalent r/docker linked post of mine quite early in a bulleted list.
Ofelia requires the docker socket, I don't need a separate container solution, that's kinda overkill.
The bash script is exactly what I'm doing right now for some time as cron wasn't a good fit and systemd-timers aren't really usable in a Docker run container.
However forwarding signals to the wrapped command, setting up a trap for child processes, capturing the exit status of the recurring command to bubble up on failure, along with stdout/stderr piped back to the supervisor process is all a bit extra when it could be simpler to have that delegated by a program instead.
Hence the post here reaching out to community to double check if anybody knew of something like that before I go and DIY such.
dorancemc@reddit
I'm moving my scheduled tasks from cron to systemd timers. With ansible, it is easy to create them.
kwhali@reddit (OP)
You can't use systemd timers within a Docker container.
To clarify that, I cannot publish an image that you can pull and run a container with preconfigured timers that are used inside the container, not unless you relax the container security considerably.
With alternative runtimes like podman that is less of an issue. I would love systemd timers, but I also have to base decisions on compatibility of the consumers of the image, that limits me from enjoying such decisions that'd allow to use systemd-timers.
Hence I reached out asking for alternatives.
karafili@reddit
Cron?
kwhali@reddit (OP)
No. I've already conveyed that cron has quirks I want to avoid.
abotelho-cbn@reddit
Can you be more specific? Are you trying to run at application or script that finds itself in a container?
kwhali@reddit (OP)
Neither?
In the example scenario there is a script to run, it does its job and exits, then it should be invoked again at a later interval like every 5 or 15 minutes (user configurable).
Think of cron but simpler time management, a program that invokes a single command at a later date. Task runs and then after it exits wait the interval and repeat.
alexkey@reddit
For running at intervals - if you are looking for some lightweight headless solutions - nothing really, maybe custom bash or python script that does sleep to make interval between calls. (Basically `for…sleep` loop) that will get you more or less precise intervals if that’s what you are after.
kwhali@reddit (OP)
Yeah I've got a bash script (I'm not the author), but it has some added complexity (trap signal to deal with
sleep) that I'd rather not carry around if I were to need this elsewhere.That script is invoked by
supervisordthrough a service config, which would send signals to manage it as a service.So while not the best reference, I'd rather something like this as the service command:
Invoking the command/process, forwarding signals, etc. That'd be simple/portable and easy to maintain without extra quirks that the bash loop with sleep or cron have?
I suppose in this case I could also have the service command run
getmail-service.sh && exec sleep 25mwith supervisord autorestarting the service when it exits (any failures would behave like a typical service command and go into unhealthy status). Still it'd be nice to have a command likerecur/repeatso I'm not dependent upon a shell or service manager for running a command at intervals.alexkey@reddit
Then just do Python. It still will need signal handling, but that is a lot simpler to do and manage than traps in bash. Otherwise I feel you are looking for such a niche tool that it may be doesn’t exist (yet) or is very very little known.
kwhali@reddit (OP)
Yeah I have considered writing my own command in Rust.
Like Python it's not that difficult to implement the basics, but there's a good chance I don't do something right with the implementation (best I can do is look at a few other projects I guess), so I tend to prefer more established projects where possible.
I came across
snoozewhich seemed close to what I wanted (snooze -t timefile -M 25 my-command), however: - Thetimefileneeds to be created in advanced with mtime set back 25 minutes (for the first run to be immediate), then you need to update the mtime again to set the present time after each run ofmy-command, while relying upon a supervisor to auto restart the service (with that samesnoozecommand)... -snoozeavoids the need to forward signals and stdout/stderr along with capturing the exit code of the command, by instead sleeping before running the command. But-t timefilecomplexity is necessary to stray from the cron styled time to sleep until. Kind of defeats the point.I'll probably just implement my own program for this, I just didn't think it'd be that niche (but I guess outside of containers, if systemd is available
systemd-timershas you covered already).michaelpaoli@reddit
Well, if you want much more stand-alone, you can do self-rescheduling at jobs.
kwhali@reddit (OP)
Yeah someone suggested the
atcommand and I've responded to that.It's interesting but it relies upon a daemon service, in addition to the self-rescheduling being a bit verbose and "hacky". Still interesting and viable :)
When I do have service management like
supervisordfor example, it's better to manage what user the process runs as through that. Starting/stopping a scheduledatjob also doesn't integrate as cleanly due to that reliance upon a daemon service.snoozelooks like what I've been looking for.toakao@reddit
You need to run a scheduler sidecar container with the app or run a standalone scheduler container like chadburn. But using chadburn means giving access to docker’s socket so you’re trusting the app developers with root on the docker host.
https://github.com/PremoWeb/chadburn
Depending on your pain tolerance, running KinD or K3S would give you a proper Cronjob type object.
kwhali@reddit (OP)
Yeah so that's like Ofelia (EDIT: Oh it's a fork of ofelia and thus has the same cron scheduling quirks I want to avoid).
I don't really want that kinda solution, no need for a docker socket when it's all in the same container. The intent was to bundle such within a single container image when this functionality is needed (
docker-mailserveris one that comes to mind).The use-case I'm describing is usually considered an anti-pattern, but is sometimes justified for convenience (when you're not the downstream user of the image/service), along with reducing complexity for some integrations when building an image that is focused on logical service (such as a mail server vs a massive user-side config and maintenance/support woes).
Honestly if it was for my own internal/personal use instead of public, I'd probably just go with Podman which can leverage systemd smoothly.
It's much less of a concern when I only need to think about myself, I'd have much more flexibility then :)