[systemd-devel] mount-on-demand for backups; hooks for indicating success/failure
Lennart Poettering
lennart at poettering.net
Fri Mar 31 10:01:11 UTC 2017
On Thu, 09.03.17 15:53, Jonathan Dowland (jon+systemd-devel at alcopop.org) wrote:
> Hey,
>
> I have some backup services which depend on mounts. I want those
> filesystems unmounted when the backup jobs are not running. This is
> easily achieved with StopWhenUnneeded.
>
> I also want to trigger the backup jobs to start when I attach my
> external HDD. This is reasonably simple by adding WantedBy=<device>
> to the backup service (*not* the mount unit, or it will never be
> auto-unmounted).
>
> So far so good!
>
> However, this is a headless box and I want to blink an LED when certain
> jobs are running, finish or fail. So I need to execute commands in
> certain situations. Job failure is easy, I can use OnFailure= and set up
> a oneshot service. Job started isn't too bad, I add a ExecStart=-
> to my backup service before the real one.
>
> Signalling "device is safe to remove" I have not figured out.
> Using a chain of blah.device -> blah.mount -> backup-blah.service units,
> "safe to remove" LED should only happen after the mount has completed
> unmounting, successfully. Is there an existing "hook" or place that I
> could put that in this situation?
On recent systemd versions you can plug in a script in ExecStop= of
your backup service, and check the $SERVICE_RESULT env var which tells
you the success state of the service, which you can then use to set
any LEDs you like.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list