systemd services, and queue management?

I’ve been increasingly using systemd timers as a replacement for cron jobs. The fact that you get free logging is great, and also the fact that you don’t have to care about multiple instances running simultaneously.

However, sometimes I would be interested in more complex scenarios, such as:

  • I’d like to trigger a full run of the service unit: if the service is not running, it should be started immediately. If it’s currently running, it should be started again when it terminates.
  • Same as the above, but with queue coalescing: If I do the above multiple times in a row, I only want the guarantee that there’s one full run of the service after the last time I triggered it (typical scenario: each run processes all pending events, so there’s no point in running multiple times).

Is this doable with systemd? If not, how do people do that outside of systemd?

4 thoughts on “systemd services, and queue management?

  1. Not possible with a single `systemctl` command on a normal unit. Looking at the `–job-mode` option might give a little insight. You could create a transient unit which runs After though. I assume `job.service` uses `Type=oneshot`, and not `Type=simple`.

    systemd-run –property After=job.service — systemctl start job.service

    This command implements the latter request (queue coalescing). If you don’t want this queue coalescing… you’d need to write a little daemon to serialize requests. Just bump a counter for each request. I believe this is within bash’s capability e.g. with `trap SIGCHLD` (possibly requiring `set +o monitor`?), and `read` from a named pipe.

    I don’t think `bash` can do sockets well enough to be launched as a systemd socket activated service though. `ncat` or even and `socat` don’t seem to help either.

  2. Ah, that was wishful thinking on my part then. Sounds like `–property` only works for resource control properties.

Comments are closed.